How to split a byte into bits so you can check whether bit X is 1 or 0

Hi everyone,

Can someone please explain to me how can I split a byte into separate bits?

I want to check whether a particular bit is 1 on 0. For example, I want to check whether bit 5 within a byte is 1 or 0 or bit 7 etc.

I know about Bitwise operators but I just don't know how to utilize them to get what I want.

Can someone help?

1
2
unsigned char byte = something;
bool fiftDigitIsOne = byte & 16 // 16 = 25-1 
Or
http://www.cplusplus.com/reference/stl/bitset/
Last edited on
Topic archived. No new replies allowed.