coverting ushort to two Byte
-
hi I am facing a problem. i am having a ushort value (ushort val), and i want to campare it with two byte values(byte b1, b2). how can i do it? :confused: if I can convert the ushort to two seperate bytes or vice versa the problem can be solved. i.e. the ushort which is made up of two bytes is to be decomposedinto two seperate bytes thanking in anticipation mahesh
-
hi I am facing a problem. i am having a ushort value (ushort val), and i want to campare it with two byte values(byte b1, b2). how can i do it? :confused: if I can convert the ushort to two seperate bytes or vice versa the problem can be solved. i.e. the ushort which is made up of two bytes is to be decomposedinto two seperate bytes thanking in anticipation mahesh
Use simple mathematics:
byte x = 1;
byte y = 1;
ushort z = 257;
if (z == (x * 256 + y))
{// ushort equals the composition of two bytes
}
-
hi I am facing a problem. i am having a ushort value (ushort val), and i want to campare it with two byte values(byte b1, b2). how can i do it? :confused: if I can convert the ushort to two seperate bytes or vice versa the problem can be solved. i.e. the ushort which is made up of two bytes is to be decomposedinto two seperate bytes thanking in anticipation mahesh
byte hi = (byte)((val >> 8) & 0xff);
byte lo = (byte)(val & 0xff);xacc-ide 0.0.10 now with C#, MSIL, C and HLSL coloring - Screenshots
-
hi I am facing a problem. i am having a ushort value (ushort val), and i want to campare it with two byte values(byte b1, b2). how can i do it? :confused: if I can convert the ushort to two seperate bytes or vice versa the problem can be solved. i.e. the ushort which is made up of two bytes is to be decomposedinto two seperate bytes thanking in anticipation mahesh