title: How to convert from Int64 to hex and from hex to byte in c#
body: <p>I am trying to send a byte array to micro controller over serial port. This is an example array which can successfully communicate with micro controller: </p>
  
  <p><code>byte[] getCommandArray = new byte[7] { 0x02, 0x0D, 0x01, 0x03, 0x30, 0x44, 0x03 };</code></p>
  
  <p>What I need to do is read different values from database, store them in a byte array send this array to the serial port. I read values from database as <code>Int64</code>. Also for a successful communication I need to convert these values to hex. For example if I read 13 from the database I need to write this to my array as 0x0D. I can convert 13 to 0x0D as hex string but I can't convert this to <code>byte</code>. If you have any other suggestions than this logic I would be appreciated. </p>