Back In the print window choose "Save as PDF" as the destination
NOTE.CS

Decimal to Binary

1 topic · 28 Nov 2026
1

Decimal to Binary

Problem Solving

Divide by 2 repeatedly and read the remainders from bottom to top. Example: 13 = 1101

Solution 1: Repeated division · C++
int n = 13;
string bin = "";
while(n > 0){
    bin = char('0' + n % 2) + bin;
    n /= 2;
}
cout << bin; // 1101
Solution 2: bitset · C++
#include <bitset>
cout << bitset<8>(13); // 00001101
Binary to Decimal · C++
string b = "1101";
int dec = 0;
for(char c : b)
    dec = dec * 2 + (c - '0');
cout << dec; // 13