Convert Int to 2 Byte Array C# .Net

  • Thread starter Thread starter carlospedr
  • Start date Start date
C

carlospedr

I'm sending ESC sequences to a printer, one of these sequences include
a parameter that is "2 byte integer", in order to send it to the
printer I have to convert an int to 2 byte integer, how do I do this?
Thank's for the help,
Carlos Pedro
 
Thank you very much, you should've called me stupid...

I wanted a 2 Byte Array not a 2 Byte int, however... the
BitConverter.GetBytes(i) function does it...

Thank you...
 
Hi,

You can use BitConverter.GetBytes( yourInt )

How are you sending it? maybe you do not need to separate it in bytes
 
You mean that you need to split a 16 bit number into two bytes?

ushort num = 42;
byte hi = (byte)(num >> 8);
byte lo = (byte)(num & 255);
 
Yes, but I've sorted it out, there is a a function in the .Net
Framework that does that.

Thank's any way.
 
Back
Top