WikiGalaxy

Personalize

Binary Representation Basics

Understanding Binary Numbers

Binary System:

The binary number system is base-2, using only digits 0 and 1. Each digit is referred to as a bit.

Converting Decimal to Binary:

To convert a decimal number to binary, divide the number by 2 and record the remainder. Repeat with the quotient until it is zero, then read the remainders in reverse.


      // Decimal to Binary Example
      int decimal = 10;
      String binary = Integer.toBinaryString(decimal);
      System.out.println(binary); // Output: 1010
    

Console Output:

1010

Binary Arithmetic Operations

Addition:

Binary addition follows the same rules as decimal addition but is simpler as it involves only two digits. The possible sums are 0+0=0, 0+1=1, 1+0=1, and 1+1=10 (which is 0 with a carry of 1).


      // Binary Addition Example
      int a = 0b1010; // 10 in decimal
      int b = 0b1100; // 12 in decimal
      int sum = a + b;
      System.out.println(Integer.toBinaryString(sum)); // Output: 10110
    

Console Output:

10110

Binary Subtraction

Subtraction:

Binary subtraction uses borrowing, similar to decimal subtraction. If the top bit is smaller than the bottom bit, borrow 1 from the next left bit.


      // Binary Subtraction Example
      int a = 0b1100; // 12 in decimal
      int b = 0b1010; // 10 in decimal
      int difference = a - b;
      System.out.println(Integer.toBinaryString(difference)); // Output: 10
    

Console Output:

10

Binary Multiplication

Multiplication:

Binary multiplication is similar to decimal multiplication. Multiply each bit of one number by each bit of the other, then add the results, shifting them according to their position.


      // Binary Multiplication Example
      int a = 0b101; // 5 in decimal
      int b = 0b11;  // 3 in decimal
      int product = a * b;
      System.out.println(Integer.toBinaryString(product)); // Output: 1111
    

Console Output:

1111

Binary Division

Division:

Binary division is similar to long division in decimal. It involves dividing the dividend by the divisor, subtracting the result, and bringing down the next bit.


      // Binary Division Example
      int dividend = 0b1100; // 12 in decimal
      int divisor = 0b11;    // 3 in decimal
      int quotient = dividend / divisor;
      System.out.println(Integer.toBinaryString(quotient)); // Output: 100
    

Console Output:

100

logo of wikigalaxy

Newsletter

Subscribe to our newsletter for weekly updates and promotions.

Privacy Policy

 • 

Terms of Service

Copyright © WikiGalaxy 2025