c - How do I convert a char array [example 42] to the int equivilant [int 42] using bit manipulation? -


say have string 42\0 0b0011010000110001000000000 [or array without null terminator 42 0b00110100001100010] , want convert 42 0b00101010 bit manipulation. how go this?

in nutshell, without checks number digit, negative, or out of range, can this:

int myatoi( const char * s ) {     int result = 0;     while( *s )     {         result <<= 1;         result += (result << 2);         result += (*s++ & 0x0f);     }     return result; } 

caveat: use of addition doesn't strictly meet requirement achieved bit operations.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -