Domanda

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?

È stato utile?

Soluzione

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 
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top