Public Group

# Getting the less significant bit of a 16 bit integer

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

## Recommended Posts

Hey, Any ideas on how to get the less significant bit of a 16 bit integer ? Thanks

##### Share on other sites
short i = 0xf00d;
i &= 1;

##### Share on other sites
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 on other sites
Quote:
 Original post by AcePiloti 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 1001nLSB     = 0000 0000 0000 0001  0011 0000 0011 1001& 0000 0000 0000 0001---------------------= 0000 0000 0000 0001

Thanks I got it.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 10
• 12
• 10
• 11
• 13
• ### Forum Statistics

• Total Topics
634095
• Total Posts
3015477
×