When I try and convert my binary string to int I am receiving a couple of mistakes that I can not figure out. First I am reading from a file and the leading zeros are not showing up when I convert and the new line is showing zero.
This code I am using from this questions: Convert binary string to hexadecimal string C
char* binaryString[100]; // convert binary string to integer int value = (int)strtol(binaryString, NULL, 2); //output string as int printf("%i \n",value) My txt file and what I am expecting as an output:
00000000 000000010001001000111010 00000000000000000000000000000001 101010111100110100110001001001000101 What I get:
0 0 70202 1 -1127017915
strtol()is useful for error detection/recovery.printf("%s\n", binaryString)101010111100110100110001001001000101is a 36-bit number without a sign. Do expect to store that unchanged in an signed integer less than 37-bit?intis often 32-bit.