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.
// Function to convert decimal to binaryvoid decimalToBinary(int decimal) {// Cannot store numbers larger than 32 bitsint binary[32];int i = 0;// Continue dividing by 2 until quotient becomes 0while (decimal > 0) {binary[i] = decimal % 2;decimal = decimal / 2;i++;}// Print binary array in reverse orderfor (int j = i - 1; j >= 0; j--) {printf("%d", binary[j]);}}
made by billy | source code | @b9llach