integer into binary in c sharp

  • Thread starter Thread starter mei xiao
  • Start date Start date
M

mei xiao

Hi, there,

I want to change an integer into 4 bytes in c sharp, what should I do? Thank
you.

-May
 
Try this


int myint = 2345;

byte [] mybytes = new byte[4];

int i, shift;
for(i = 0, shift = 24; i < 4; i++, shift -= 8)
mybytes = (byte)(0xFF & (myint >> shift));
 
I want to change an integer into 4 bytes in c sharp, what should I do?

Use the shift operators or the BitConverter class.



Mattias
 
Back
Top