Search
 
SCRIPT & CODE EXAMPLE
 

CPP

number to binary string c++

  ==== Convert number to binary string C++ ======
 int n = 100;
 string s1=""
//Method 1:
 string s1 = bitset<8>(n).to_string(); // 01100100
//Method 2
 while(n) {
 	s1 += (n%2) + '0';
    n /= 2;
 }
 reverse(s1.begin(),s1.end()); // 1100100
Comment

convert long int to binary string c++

auto int_bits_size = 32; // maximum number of bits for the integer
auto some_integer = 123456789;
std::string str = std::bitset<int_bits_size>(some_integer).to_string();
Comment

convert int to binary string c++

std::string str = std::bitset<8>(123).to_string();
Comment

PREVIOUS NEXT
Code Example
Cpp :: copy substring to another string c++ 
Cpp :: c++ random number generator uniform distribution 
Cpp :: quick sort c++ 
Cpp :: user defined key for map in c++ 
Cpp :: c++ find sum of vector 
Cpp :: how to declrae an array of size 1 
Cpp :: c++ print current time 
Cpp :: stack implementation using linked list in cpp 
Cpp :: cout was not declared in this scope 
Cpp :: c++ print to standard error 
Cpp :: how to print fixed places after decimal point in c++ 
Cpp :: string count occurrences c++ 
Cpp :: c++ random 
Cpp :: c++ matrix as argument 
Cpp :: string input with space c++ stl 
Cpp :: apply pca to dataframe 
Cpp :: if even number c++ 
Cpp :: c++ loop through string 
Cpp :: adding elements to a vector c++ 
Cpp :: how to iterate from second element in map c++ 
Cpp :: cpp unions 
Cpp :: max value of double c++ 
Cpp :: number of words in c++ files 
Cpp :: nth node from end of linked list 
Cpp :: c++ segmented sieve 
Cpp :: why are inline keyword in header c++ 
Cpp :: change int to string c++ 
Cpp :: c++ binary search 
Cpp :: c++ vectors 
Cpp :: what is c++ standard library 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =