What is the most portable way to read and write the highest bit of an integer in C?
This is a Bloomberg interview question. I didn’t give best answer at that time. Can anyone please answer it?
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.
If the type is unsigned, it’s easy:
For signed values, I know no way. If you find a way, it would answer several unanswered questions on SO:
C question: off_t (and other signed integer types) minimum and maximum values
Is there any way to compute the width of an integer type at compile-time?
Maybe others.