Storing the number 42790 in two bytes??

  • Thread starter Thread starter Max Adams
  • Start date Start date
M

Max Adams

All, I have a ushort data type which holds the number 42790, I need to write
this number to a binary file so it only takes up two bytes. As a ushort is
an Unsigned 16-bit integer, i know it will fit into two bytes, however i'm
unsure of how exactly to do it.

Can anyone suggest the best way to do this?

PT
 
ushort i = 42790;
byte [] a = System.BitConverter.GetBytes(i);

or

BinaryWriter bw;
bw.Write(i);
 
Back
Top