Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++: binary std::string to decimal

Tags:

c++

I want to convert 64 bit binary string to 64 bit integer (unsigned). Is there any library function to do that in C++ ?

Edit:

I use:

main()
{
std::string st = "010111000010010011000100010001110110011010110001010111010010010110100101011001010110010101101010" ;

uint64_t number;
number = strtoull (st.c_str (),NULL,2);
cout << number << " " ;

char ch = std::cin.get();
cout << ch ;


   return 0;
}
like image 208
alessandro Avatar asked Dec 01 '22 20:12

alessandro


1 Answers

You can use strtoull() function with base 2 (there is an example if you follow the link).

like image 171
Maxim Egorushkin Avatar answered Dec 04 '22 10:12

Maxim Egorushkin