سؤال

I need to calculate if a hexadecimal number is odd or even as a C function. Is there any function to do it directly?

If not, is there a function in C to directly convert from hexadecimal to binary?

هل كانت مفيدة؟

المحلول

for hexa to binary look at this page HTOI

or you can convert for hexa to decimal look at this function strtol

and then to binary using normal methods.

to find odd or not you can use

if(x & 1 == 1)
     //it's odd
else 
    // it's even 
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top