# Binary to integer

This is a discussion on Binary to integer within the C Programming forums, part of the General Programming Boards category; &quot;Hello I have a long binary string in a char array like this char abc [] = &quot;100000001010000000110010&quot;; I need ...

1. ## Binary to integer

"Hello

I have a long binary string in a char array like this

char abc [] = "100000001010000000110010";

I need to convert this string to a long long.
I can't use atoi to convert it to long long using atoll because this string is more than 10 (11 including null termination) characters long. And starts giving me junk values.

Once I convert it to an integer I will run a program / function to convert the long long number to its equivalent radix 10 format..

Does anyone have any suggestions how I can go about this? or some other way to approach this problem

2. Use a loop. Starting at the right end of the array, the value my be computed by multiplying each digit (0 or 1) by an appropriate power of 2, and adding up.

longlongvalue = 0*1 + 1*2 + 0*4 + 0*8 + 1*16 + 1*32 ..... <until beginning of array>.

where the digits I've coloured in red are the the digits, working backward from the end of the end of the array.

3. If your compiler has 64 bit ints... it should also have an strtoull() function... which is part of the C99 standard...
Code:
```unsigned long long abcnum

abcnum = strtoull(abc,NULL,2);```