title: How can I safely convert `unsigned long int` to `int`?
body: <p>I have an app which is creating unique <strong>ids</strong> in the form of <code>unsigned long int</code>s. The app needs this precision. </p>
  
  <p>However, I have to send these <strong>ids</strong> in a protocol that only allows for <code>int</code>s. The receiving application – of the protocol – does not need this precision. So my questions is: how can I convert an <code>unsigned long int</code> to an <code>int</code>, especially when the <code>unsigned long int</code> is larger than an <code>int</code>?</p>
  
  <h3>edit:</h3>
  
  <p>The <strong>protocol</strong> only supports <code>int</code>. I would be good to know how to avoid "roll-over problems"</p>
  
  <p>The application sending the message needs to know the uniqueness for a long period of time, whereas the receiver needs to know the uniqueness only over a short period of time.</p>