<$BlogRSDUrl$>

Sunday, July 04, 2004

Encounter with HiByte, LoByte



While I was working with the ASPI32 Interface, I encountered these HiByte's and LoByte's. For a second I was stuck as I really did not know how to extract HiByte and LoByte using C#/.NET. I Turned to MSDN, after a few moment I realized... .NET does not have a way for me to extract these byte's. Yep! The Win32 World has a Macro for HiByte, LoByte, but the Managed world does not have a equivalent way :-(

Finally, I decided to write my own.
For a LoByte I had to extract low order(least significant) byte, and for a hi Byte I had to extract high order (Most Significant) Byte


public int LoByte(int word)
{
return (Word & 0xFF);
}

public int HiByte(int Word)
{
return ((word & 0xFF00) / 0x100);
}



If u are inquisitive, about what happens Behind the scenes, here you go

LoByte
[let word=1234, i.e. 0001 0010 0011 0100]

0001 0010 0011 0100
AND
0000 0000 1111 1111
-------------------
0000 0000 0011 0100


HiByte
[word=1234]

0001 0010 0011 0100
AND
1111 1111 0000 0000
-------------------
0001 0010 0000 0000
DIV
0001 0000 0000 0000
-------------------
0001 0010 0000 0000


Pretty Simple :-)


posted by Logu Krishnan : 12:08 PM

Comments:
hi darren, thanks for correcting me :-0
and chris... I think bitconverter is the next alternative.... :-)


 
Post a Comment

This page is powered by Blogger. Isn't yours?