Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR 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
 
PREVIOUS NEXT
Tagged: #number #binary #string
ADD COMMENT
Topic
Name
5+3 =