Lets say I have an int variable n = 8. On most machines this will be a 32 bit value. How can I only get the lower 8 bits (lowest byte) of this in binary? Also how can I access each bit to find out what it is?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Note a few things:
unsignedtypes&operator0xFFbecause in binary it has its low 8 bits turned on and the rest 0To access a certain bit of a number, say the
kth bit:Now,
kthbitwill be 0 if thekth bit ofnis 0, and some positive number (2**k) if thekth bit ofnis 1.