← Back

Binary & Bits

Simulation Speed:1x

Binary Conversion

Binary is a base-2 number system where numbers are represented using only 0s and 1s. Each position represents a power of 2, and we can convert decimal numbers to binary through repeated division by 2.

Conversion Steps:

C Code Example:

// Function to convert decimal to binary
void decimalToBinary(int decimal) {
// Cannot store numbers larger than 32 bits
int binary[32];
int i = 0;
// Continue dividing by 2 until quotient becomes 0
while (decimal > 0) {
binary[i] = decimal % 2;
decimal = decimal / 2;
i++;
}
// Print binary array in reverse order
for (int j = i - 1; j >= 0; j--) {
printf("%d", binary[j]);
}
}

made by billy | source code | @b9llach