Jump to content
  • Advertisement
Sign in to follow this  
CRACK123

Getting the less significant bit of a 16 bit integer

This topic is 4886 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
i didnt test it, but it might work.



// union to represent a number. Utilised by the getLow() function.
typedef union number
{
short n16bit;
char n8bit;
}number;

// gets the lower 8 bits of the 16 bit integer.
char getLow(short num)
{
number ret;
ret.n16bit = num;
return ret.n8bit
}


Share this post


Link to post
Share on other sites
Quote:
Original post by AcePilot
i didnt test it, but it might work.

*** Source Snippet Removed ***


That will return the lowest BYTE.

bakery2k1 has it right.

int nSomeInt = 12345;
int nLSB = nSomeInt & 0x1;

And here's why:

nSomeInt = 0011 0000 0011 1001
nLSB = 0000 0000 0000 0001

0011 0000 0011 1001
& 0000 0000 0000 0001
---------------------
= 0000 0000 0000 0001

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!