I need to store a value between 0-15 in C , 4 bits are enough for this. How can I just have a variable of 4 bits? Space is a constraint here
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.
Consider using a
char. Yeah, it’s 8-bits, but you can use the bit shift operators (<<and>>) to store values in the other 4 bits.Edit: Per the comments below, an
unsigned charis, in fact, preferable overcharto avoid issues with the sign bit.