atoi not converting properly

i need to reverse the bits of 0x43 and convert it back to an int.
when i use atoi it just outputs the same value 1100001.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int divisor = 0x43;
int r_divisor = bit_revers(divisor);
r_divisor = ((r_divisor >> 25) & 0x7F);
bitset<7> divisor_bit(divisor);	
bitset<7> r_divisor_bit(((r_divisor >> 25) & 0x7F));

char div_buff[33];
char div_out[9] ;
div_out[8]= '\0';
_itoa_s(r_divisor,div_buff,2);
strncpy_s(div_out,div_buff, 7);
int test = atoi(div_out);

//divisor = fromBinary(div_out); this works
std::cout << "to binary using itoa " << div_out << std::endl;
//std::cout << "from binary " << divisor << std::endl;
std::cout << "to int atoi " << test << std::endl;

the result should be 97 in decimal.
1
2
3
// this code works
int test = strtol(div_out, NULL, 2);
// test equals to 97. 


found the answer to my question here

http://stackoverflow.com/questions/23596988/binary-string-to-integer-with-atoi
Last edited on
Topic archived. No new replies allowed.