# Demystifying Number Systems: An Engineer's Guide to Binary, Octal, and Hexadecimal

Imagine you were born with only two fingers, one on each hand. How would your everyday life change? When you went to the store to buy apples, how would you count them? You might count "zero, one, two," but you would run out of physical fingers almost instantly. To count higher, you would have to invent a system where a single mark in a new position represents a bundle of items you have already counted.

Humans settled on a base 10 number system primarily because we evolved with ten fingers. We count in groups of tens, hundreds, and thousands without giving it a second thought. But computers do not have fingers. They are built out of millions of subatomic electronic switches known as transistors. A transistor can exist reliably in only two physical states: fully off or fully on.

Because a switch has only two stable states, computers naturally operate using a base 2 number system, which we call binary. Everything you see on a digital screen, including high definition video, complex 3D graphics, sound files, and software programs, boils down to millions of tiny switches turned ON or OFF.

Understanding how computers represent numbers is one of the most important foundational skills in software engineering. Whether you are debugging memory leaks, working with low level networking protocols, manipulating graphics pixels, or configuring system permissions, number systems appear everywhere in software engineering.

## What is a Number System?

At its core, a number system is a structured framework for counting, representing quantities, and performing mathematical operations. It defines a set of symbols and rules for combining those symbols to express values.

To understand any number system, you need to understand three core terms:

*   **Symbols**: The individual graphics or characters used to represent values. In our everyday language, we use symbols like 0, 1, 2, 3 and so on.
    
*   **Digits**: The specific symbols used within a given number system.
    
*   **Base (Radix)**: The total number of unique digits or symbols available in that system.
    

What does the base actually mean? The base tells you how many unique single digit symbols exist before you run out of digits and must combine them to create larger numbers.

Consider how you count in our everyday decimal system (base 10):

$$0, 1, 2, 3, 4, 5, 6, 7, 8, 9$$

Once you reach 9, you have used every available single digit symbol in base 10. To represent the next quantity, you wrap back around to \\(0\\) in the current position and place a 1 to the left of it, giving you \\(10\\). The \\(1\\) in \\(10\\) represents one complete bundle of ten items.

Now imagine a number system with a base of 4. Its available digits would only be:

$$0,1,2,3$$

Counting in base 4 looks like this:

$$0,1,2,3,10,11,12,13,20,21..$$

Notice how after reaching 3, the system runs out of symbols. The next number is written as \\( 10_4 \\) (read as "one zero in base 4"), which represents four total items. The base defines the grouping size of the number system.

*   Base 10 (Decimal): Groups of 10 → \[0, 1, 2, 3, 4, 5, 6, 7, 8, 9\]
    
*   Base 4: Groups of 4 → \[0, 1, 2, 3\]
    
*   Base 2 (Binary): Groups of 2 → \[0, 1\]
    

## Understanding Positional Value

Why can we express gigantic numbers like one billion using only ten digits? The answer lies in positional notation.

In a positional number system, the value of a digit depends not only on the symbol itself, but also on its position or place within the sequence of digits. The position determines the power of the base by which that digit is multiplied.

### Positional Values in Decimal

Let us examine the decimal number \\(375\\). We read this as three hundred seventy five. Why?

The rightmost position represents the base raised to the power of \\(0\\), which is \\(10_0 = 1\\). Moving left, each position multiplies the place value by the base (\\(10\\)).

| Digit Position | 2 | 1 | 0 |
| --- | --- | --- | --- |
| Base Power | \\(10^2\\) | \\(10^1\\) | \\(10^0\\) |
| Place Value | 100 | 10 | 1 |
| Digit | 3 | 7 | 5 |

Mathematically, we calculate the total value as:

$$375 = (3 \times 100) + (7\times10) + (5\times1) = 300 + 70 + 5 = 375$$

### Positional Values in Binary

Binary follows the exact same positional rule. The only difference is that the base is \\(2\\) instead of \\( 10 \\) . Each position to the left increases by a power of \\(2\\).

Consider the binary number \\(1101_2\\):

| Digit Position | 3 | 2 | 1 | 0 |
| --- | --- | --- | --- | --- |
| Base Power | \\(2^3\\) | \\(2^2\\) | \\(2^1\\) | \\(2^0\\) |
| Place Value | 8 | 4 | 2 | 1 |
| Binary Digit | 1 | 1 | 0 | 1 |

We evaluate its value in decimal by summing the products of each digit and its position weight:

$$1101_2 = (1\times2^3) + (1\times2^2) + (0\times2^1) + (1\times2^0)$$

$$1101_2 = (1\times8) + (1\times4) + (0\times2) + (1\times1) = 8+4+0+1 = 13_{10}$$

Positional notation is extraordinarily powerful because it allows a small, finite set of symbols to represent infinitely large values simply by extending digits to the left. Ancient systems like Roman numerals lacked a true positional place value system, which made arithmetic complex and cumbersome.

## Types of Number Systems

While you can construct a number system for any integer base, software engineering relies heavily on four specific systems: Decimal, Binary, Octal, and Hexadecimal.

### Decimal (Base 10)

*   **Base**: \\(10\\)
    
*   **Allowed Digits**: \\(0, 1, 2, 3, 4, 5, 6, 7, 8, 9\\)
    
*   **Usage**: Everyday human communication, financial calculations, and high level application inputs/outputs.
    

### Binary (Base 2)

*   **Base**: \\( 2 \\)
    
*   **Allowed Digits**: \\(0, 1\\)
    
*   **Usage**: Machine level hardware operation, digital logic circuits, CPU registers, low level protocols, and boolean logic.
    

### Octal (Base 8)

*   **Base**: \\(8\\)
    
*   **Allowed Digits**: \\(0, 1, 2, 3, 4, 5, 6, 7\\)
    
*   **Usage**: Unix file permission representations (for example `chmod 755`), legacy computing systems, and shorthand for 3-bit binary groups.
    

### Hexadecimal (Base 16)

*   **Base**: \\(16\\)
    
*   **Allowed Digits**: \\(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F\\)
    
*   **Digit Mapping**: \\(A = 10, B = 11, C = 12, D = 13, E = 14, F = 15\\)
    
*   **Usage**: Memory address formatting, color representation in web applications (`#FF5733`), assembly language, inspection of binary data in hex editors, and network configuration (IPv6, MAC addresses).
    

### Value Comparison Table (0 to 31)

The following reference table maps values from \\(0\\) through \\(31\\) across all four core number systems.

| Decimal (Base 10) | Binary (Base 2) | Octal (Base 8) | Hexadecimal (Base 16) |
| --- | --- | --- | --- |
| 0 | 000000 | 00 | 00 |
| 1 | 000001 | 01 | 01 |
| 2 | 000010 | 02 | 02 |
| 3 | 000011 | 03 | 03 |
| 4 | 000100 | 04 | 04 |
| 5 | 000101 | 05 | 05 |
| 6 | 000110 | 06 | 06 |
| 7 | 000111 | 07 | 07 |
| 8 | 001000 | 10 | 08 |
| 9 | 001001 | 11 | 09 |
| 10 | 001010 | 12 | 0A |
| 11 | 001011 | 13 | 0B |
| 12 | 001100 | 14 | 0C |
| 13 | 001101 | 15 | 0D |
| 14 | 001110 | 16 | 0E |
| 15 | 001111 | 17 | 0F |
| 16 | 010000 | 20 | 10 |
| 17 | 010001 | 21 | 11 |
| 18 | 010010 | 22 | 12 |
| 19 | 010011 | 23 | 13 |
| 20 | 010100 | 24 | 14 |
| 21 | 010101 | 25 | 15 |
| 22 | 010110 | 26 | 16 |
| 23 | 010111 | 27 | 17 |
| 24 | 011000 | 30 | 18 |
| 25 | 011001 | 31 | 19 |
| 26 | 011010 | 32 | 1A |
| 27 | 011011 | 33 | 1B |
| 28 | 011100 | 34 | 1C |
| 29 | 011101 | 35 | 1D |
| 30 | 011110 | 36 | 1E |
| 31 | 011111 | 37 | 1F |

## Why Computers Use Binary

Why do computers use base 2 instead of base 10? Wouldn't a decimal computer be much more convenient for humans?

To answer this, we must look at the hardware components inside modern microprocessors. At the silicon level, computer memory and processors consist of billions of microscopic transistors that act as electronic switches.

*   High Voltage State (~5V or ~3.3V) ----> Represents '1' (ON)
    
*   Low Voltage State (~0V or ~0.5V) ----> Represents '0' (OFF)
    

In physical hardware, precise electric voltages fluctuate constantly due to temperature variations, manufacturing flaws, and electromagnetic interference.

If engineers built a base 10 computer, the hardware would need to distinguish between 10 distinct voltage levels (for instance, 0V, 0.5V, 1.0V, up to 4.5V). A small electrical spike or drop of just 0.3 volts could cause the computer to misread a digit \\(4\\) as a \\(3\\) or \\(5\\), leading to corrupted data and crashes.

Binary eliminates this problem. By defining only two states (a high voltage threshold for \\(1\\) and a low voltage threshold for \\(0\\)), hardware components gain immense noise tolerance. The system only needs to determine whether a voltage level is "generally high" or "generally low". This simple distinction makes modern digital computing extraordinarily reliable and scalable.

## Why Octal and Hexadecimal Exist

Although binary is ideal for electronic hardware, it is difficult for human engineers to read, write, and remember.

Imagine inspecting a computer's system memory and seeing a raw string of binary data like this:

$$11011110101011010110101110001111_2$$

It is nearly impossible for a human to spot a mistake or communicate this number verbally to a colleague without making a mistake.

This is where Octal and Hexadecimal come to the rescue. They act as human readable shortcuts for binary strings.

Because \\(8\\) and \\(16\\) are exact integer powers of \\( 2 \\) , there is a direct mathematical relationship between binary bits and octal/hexadecimal digits:

$$2^3 = 8 \implies \text{3 binary bits correlate exactly to 1 octal digit}$$

$$2^4 = 16 \implies \text{4 binary bits correlate exactly to 1 hexadecimal digit}$$

Let us look at how much simpler the previous 32-bit binary number becomes when grouped into 4-bit clusters (nibbles) and written in hexadecimal:

| Binary | 1101 | 1110 | 1010 | 1101 | 0110 | 1011 | 1000 | 1111 |
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
| Hexadecimal | D | E | A | D | 6 | B | 8 | F |

The long, unreadable string of 32 binary digits collapses into just 8 hexadecimal characters: `DEAD6B8F`. It takes up far less space on a monitor and reduces human errors.

### Real World Applications of Hexadecimal and Octal

*   **Memory Addresses**: Operating systems display RAM locations as hexadecimal numbers (e.g., `0x7FFF5FBFF010`).
    
*   **HTML/CSS Colors**: Web colors use 24-bit hexadecimal values representing Red, Green, and Blue channels (`#FF0000` for pure red).
    
*   **MAC Addresses**: Hardware network card identifiers use six pairs of hex digits (`00:1A:2B:3C:4D:5E`).
    
*   **IPv6 Addresses**: Next generation Internet Protocol addresses use 128-bit values split into eight 16-bit hexadecimal blocks (`2001:0db8:85a3:0000:0000:8a2e:0370:7334`).
    
*   **Unix File Permissions**: File access modes in Unix systems use octal flags (e.g., `777` grants read, write, and execute permissions).
    
*   **Hex Editors**: Developers use hex editors to inspect binary files, executable code, and raw disk sectors.
    

## Number Conversion Fundamentals

Before memorizing algorithmic formulas for conversions, it helps to understand the underlying logic.

Converting a number from one base to another is simply a re-packaging process. You are taking a fixed quantity of items and re-grouping them according to the rules of a new base.

When converting **from Decimal to another base**, you are answering the question: "How many bundles of size \\( Base^k, \dots, Base^2, Base^1, Base^0 \\) can I pull out of this number?" This is why the standard algorithm relies on **repeated division**. Division extracts remainder values that become digits in the new base from right to left.

When converting **from another base to Decimal**, you are working in reverse: evaluating positional weights and summing them up. This requires **positional multiplication**.

### Decimal to Binary

To convert a decimal whole number into binary, we use the **repeated division-by-2 method**.

#### Algorithm Steps

1.  Divide the decimal number by \\( 2 \\) .
    
2.  Record the integer quotient and the remainder (\\(0\\) or \\(1\\)).
    
3.  Take the quotient and divide it by \\( 2 \\) again.
    
4.  Repeat this process until the quotient becomes \\(0\\).
    
5.  Write out the remainders in **reverse order** (from the last remainder calculated to the first).
    

#### Worked Example: Convert \\(43_{10}\\) to Binary

43÷2=21remainder 1(Least Significant Bit - LSB)21÷2=10remainder 110÷2=5remainder 05÷2=2remainder 12÷2=1remainder 01÷2=0remainder 1(Most Significant Bit - MSB)

Reading the remainders from bottom to top (MSB to LSB), we get:

#### Code Implementation

```java
public class DecimalToBinary {
    public static String convertDecimalToBinary(int decimal) {
        if (decimal == 0) {
            return "0";
        }
        
        StringBuilder binaryResult = new StringBuilder();
        int currentNumber = decimal;
        
        // Loop until the quotient becomes 0
        while (currentNumber > 0) {
            int remainder = currentNumber % 2; // Calculate remainder (0 or 1)
            binaryResult.append(remainder);   // Append remainder to result string
            currentNumber = currentNumber / 2; // Divide quotient by 2
        }
        
        // Reverse string to order remainders from MSB to LSB
        return binaryResult.reverse().toString();
    }

    public static void main(String[] args) {
        int number = 43;
        System.out.println("Decimal " + number + " in Binary is: " + convertDecimalToBinary(number));
    }
}
```

### Binary to Decimal

To convert a binary number back to decimal, we use **positional expansion**. Multiply each binary digit by \\( 2 \\) raised to the power of its zero-indexed position (counting from right to left), then add all the products together.

#### Worked Example: Convert \\(110101_2\\) to Decimal

Write down the positional powers of \\( 2 \\) for each digit:

#### Code Implementation

```java
public class BinaryToDecimal {
    public static int convertBinaryToDecimal(String binaryStr) {
        int decimalSum = 0;
        int length = binaryStr.length();
        
        // Iterate through each character in the string from left to right
        for (int i = 0; i < length; i++) {
            char bitChar = binaryStr.charAt(i);
            int bitValue = Character.getNumericValue(bitChar);
            
            // Exponent corresponds to distance from the rightmost edge
            int power = length - 1 - i;
            decimalSum += bitValue * Math.pow(2, power);
        }
        
        return decimalSum;
    }

    public static void main(String[] args) {
        String binary = "110101";
        System.out.println("Binary " + binary + " in Decimal is: " + convertBinaryToDecimal(binary));
    }
}
```

### Decimal to Octal

Decimal to octal conversion follows the exact same pattern as decimal to binary, but we divide by \\(8\\) instead of \\( 2 \\) .

Worked Example: Convert \\(175_{10}\\) to Octal

175÷8=21remainder 7(LSB)21÷8=2remainder 52÷8=0remainder 2(MSB)

Reading remainders from bottom to top:

#### Code Implementation

```java
public class DecimalToOctal {
    public static String convertDecimalToOctal(int decimal) {
        if (decimal == 0) return "0";
        
        StringBuilder octalResult = new StringBuilder();
        int current = decimal;
        
        while (current > 0) {
            int remainder = current % 8; // Remainder when dividing by 8
            octalResult.append(remainder);
            current /= 8;               // Reduce quotient by factor of 8
        }
        
        return octalResult.reverse().toString();
    }

    public static void main(String[] args) {
        int val = 175;
        System.out.println("Decimal " + val + " in Octal is: " + convertDecimalToOctal(val));
    }
}
```

### Octal to Decimal

To convert from octal to decimal, sum each octal digit multiplied by \\(8\\) raised to its position power.

#### Worked Example: Convert \\(346_8\\) to Decimal

#### Code Implementation

```java
public class OctalToDecimal {
    public static int convertOctalToDecimal(String octalStr) {
        int decimalSum = 0;
        int length = octalStr.length();
        
        for (int i = 0; i < length; i++) {
            int digit = Character.getNumericValue(octalStr.charAt(i));
            int power = length - 1 - i;
            decimalSum += digit * Math.pow(8, power);
        }
        
        return decimalSum;
    }

    public static void main(String[] args) {
        String octal = "346";
        System.out.println("Octal " + octal + " in Decimal is: " + convertOctalToDecimal(octal));
    }
}
```

### Decimal to Hexadecimal

To convert decimal numbers to hexadecimal, perform **repeated division by 16**. Remainders ranging from \\(10\\) to \\(15\\) must be translated to their corresponding letters (\\(\text{A}\\) through \\(\text{F}\\)).

#### Worked Example: Convert \\(942_{10}\\) to Hexadecimal

942÷16=58remainder 14⟹E(LSB)58÷16=3remainder 10⟹A3÷16=0remainder 3⟹3(MSB)

Reading from bottom to top:

$$942_{10} = 3\text{AE}_{16}$$

#### Code Implementation

```java
public class DecimalToHexadecimal {
    private static final char[] HEX_CHARS = "0123456789ABCDEF".toCharArray();

    public static String convertDecimalToHex(int decimal) {
        if (decimal == 0) return "0";
        
        StringBuilder hexResult = new StringBuilder();
        int current = decimal;
        
        while (current > 0) {
            int remainder = current % 16;
            // Lookup corresponding hex character for remainder
            hexResult.append(HEX_CHARS[remainder]);
            current /= 16;
        }
        
        return hexResult.reverse().toString();
    }

    public static void main(String[] args) {
        int number = 942;
        System.out.println("Decimal " + number + " in Hex is: " + convertDecimalToHex(number));
    }
}
```

### Hexadecimal to Decimal

Convert each hexadecimal digit to its numerical decimal equivalent, multiply by \\(16\\) raised to its position power, and sum the terms.

#### Worked Example: Convert \\(2\text{F}8_{16}\\) to Decimal

Note that \\(\text{F} = 15\\).

$$\begin{aligned} 2\text{F}8_{16} &= (2 \times 16^2) + (15 \times 16^1) + (8 \times 16^0) \\ &= (2 \times 256) + (15 \times 16) + (8 \times 1) \\ &= 512 + 240 + 8 \\ &= 760_{10} \end{aligned}$$

#### Code Implementation

```java
public class HexadecimalToDecimal {
    public static int convertHexToDecimal(String hexStr) {
        int decimalSum = 0;
        String upperHex = hexStr.toUpperCase();
        int length = upperHex.length();
        
        for (int i = 0; i < length; i++) {
            char ch = upperHex.charAt(i);
            // Convert character ('0'-'9' or 'A'-'F') to integer value
            int digitValue = "0123456789ABCDEF".indexOf(ch);
            int power = length - 1 - i;
            
            decimalSum += digitValue * Math.pow(16, power);
        }
        
        return decimalSum;
    }

    public static void main(String[] args) {
        String hex = "2F8";
        System.out.println("Hex " + hex + " in Decimal is: " + convertHexToDecimal(hex));
    }
}
```

### Binary to Octal

Converting directly from binary to octal does not require arithmetic division. Because \\(2^3 = 8\\), you can perform conversion purely through **visual bit-grouping**.

#### Algorithm Steps

1.  Start from the **rightmost bit** (LSB) and split the binary number into groups of **3 bits**.
    
2.  If the leftmost group has fewer than 3 bits, **pad it with leading zeros** on the left.
    
3.  Convert each 3-bit group into its corresponding octal digit (\\(0\\) through \\(7\\)).
    

#### Worked Example: Convert \\(1101011_2\\) to Octal

First, group into 3-bit sets starting from the right:

$$1 \quad \mid \quad 101 \quad \mid \quad 011$$

Pad the leftmost single bit with two leading zeros to complete the triplet:

$$001 \quad \mid \quad 101 \quad \mid \quad 011$$

Now translate each group:

*   \\(001_2 = 1_8\\)
    
*   \\(101_2 = 5_8\\)
    
*   \\(011_2 = 3_8\\)
    

Combine the results:

$$1101011_2 = 153_8$$

### Octal to Binary

To convert octal to binary, perform the bit-grouping process in reverse. Replace **every single octal digit** with its exact **3-bit binary representation**.

#### Worked Example: Convert \\(624_8\\) to Binary

Convert each digit individually:

*   \\(6_8 = 110_2\\)
    
*   \\(2_8 = 010_2\\) (Be sure to keep the leading zero to maintain 3 bits)
    
*   \\(4_8 = 100_2\\)
    

Concatenate the binary groups:

$$624_8 = 110010100_2$$

### Binary to Hexadecimal

Because \\(2*4 = 16\\), converting binary to hexadecimal is done by grouping bits into sets of **4 bits** (nibbles).

#### Algorithm Steps

1.  Start from the **rightmost bit** and partition the binary string into sets of 4 bits.
    
2.  Pad the leftmost group with leading zeros if it contains fewer than 4 bits.
    
3.  Replace each 4-bit block with its corresponding hexadecimal digit (\\(0\\) to \\(\text{F}\\)).
    

#### Worked Example: Convert \\(11101011001_2\\)​ to Hexadecimal

Group from right to left in sets of four:

$$111 \quad \mid \quad 0101 \quad \mid \quad 1001$$

Pad the leftmost triplet with a single zero:

$$0111 \quad \mid \quad 0101 \quad \mid \quad 1001$$

Translate each nibble:

*   \\(0111_2 = 7_{16}\\)
    
*   \\(0101_2 = 5_{16}\\)
    
*   \\(1001_2 = 9_{16}\\)
    

Combine the hex digits:

$$11101011001_2 = 759_{16}$$

### Hexadecimal to Binary

Convert each hexadecimal character into its exact **4-bit binary block**.

#### Worked Example: Convert \\(\text{B0E}_{16}\\) to Binary

Translate each character independently:

*   \\(\text{B}_{16} = 11_{10} = 1011_2\\)
    
*   \\(0_{16} = 0000_2\\) (Always write out all four zeros)
    
*   \\(\text{E}_{16} = 14_{10} = 1110_2\\)
    

Combine the binary blocks:

$$\text{B}0\text{E}_{16} = 101100001110_2$$

### Octal to Hexadecimal

Direct conversion between octal (base 8) and hexadecimal (base 16) is awkward using pure arithmetic. The easiest and fastest way to convert between them is using **Binary as an intermediary bridge**.

#### Worked Example: Convert \\(735_8\\) to Hexadecimal

**Step 1**: Convert Octal to Binary (3 bits per digit)

*   \\(7_8 = 111_2\\)
    
*   \\(3_8 = 011_2\\)
    
*   \\(5_8 = 101_2\\)
    

Intermediate Binary String: \\(111011101_2\\)

**Step 2**: Group the Binary String into 4-bit sets (from right to left)

$$1 \quad \mid \quad 1101 \quad \mid \quad 1101$$

Pad leftmost group with zeros:

$$0001 \quad \mid \quad 1101 \quad \mid \quad 1101$$

**Step 3**: Convert 4-bit blocks to Hexadecimal

*   \\(0001_2 = 1_{16}\\)
    
*   \\(1101_2 = \text{D}_{16}\\)
    
*   \\(1101_2 = \text{D}_{16}\\)
    

Result:

$$735_8 = 1\text{DD}_{16}$$

### Hexadecimal to Octal

Converting from Hexadecimal to Octal uses the same binary bridge strategy.

#### Worked Example: Convert \\(4\text{AC}_{16}\\) to Octal

**Step 1**: Expand Hex digits to 4-bit binary blocks

*   \\(4_{16} = 0100_2\\)
    
*   \\(\text{A}_{16} = 1010_2\\)
    
*   \\(\text{C}_{16} = 1100_2\\)
    

Intermediate Binary: \\(010010101100_2\\)

**Step 2**: Re-group binary string into 3-bit triplets (from right to left)

$$010 \quad \mid \quad 010 \quad \mid \quad 101 \quad \mid \quad 100$$

**Step 3**: Convert 3-bit groups to Octal digits

*   \\(010_2 = 2_8\\)
    
*   \\(010_2 = 2_8\\)
    
*   \\(101_2 = 5_8\\)
    
*   \\(100_2 = 4_8\\)
    

Result:

$$4\text{A}\text{C}_{16} = 2254_8$$

## Fractional Number Conversion

How do computers handle fractional values (numbers with decimal points, like \\(10.625_{10}\\))?

A fractional number consists of two parts separated by a radix point: an integer portion and a fractional portion.

$$10.625_{10} \implies \text{Integer Part} = 10, \quad \text{Fractional Part} = 0.625$$

### Converting the Integer Part

The integer part (10) is converted using standard division by 2:

$$10_{10} = 1010_2$$

### Converting the Fractional Part (Repeated Multiplication)

To convert the fractional component (\\(0.625\\)), we use **repeated multiplication by 2**:

1.  Multiply the fraction by \\(2\\).
    
2.  The integer portion of the result becomes the next binary fractional digit.
    
3.  Take the remaining fractional part and multiply by \\(2\\) again.
    
4.  Repeat until the fractional part becomes \\(0\\) (or until you reach your target precision level).
    

Let us convert \\(0.625_{10}\\):

$$0.625 \times 2 = 1.25 \implies \text{Integer part: } 1, \quad \text{New fraction: } 0.25$$

 $$ 0.25 \times 2 = 0.50 \implies \text{Integer part: } 0, \quad \text{New fraction: } 0.50$$

 $$ 0.50 \times 2 = 1.00 \implies \text{Integer part: } 1, \quad \text{New fraction: } 0.00 \quad (\text{Stop})$$

Read the integer parts **from top to bottom**:

$$0.625_{10} = 0.101_2$$

Combine both integer and fractional results:

$$10.625_{10} = 1010.101_2$$

## Number Systems in Java

Modern Java provides built-in syntax literals and utility functions within the `Integer` wrapper class to handle different number bases easily.

### Literal Syntax Prefix in Java

*   Binary Literals: Prefix with `0b` or `0B`
    
*   Octal Literals: Prefix with `0`
    
*   Hexadecimal Literals: Prefix with `0x` or `0X`
    

### Built-in Conversion Methods

```java
public class JavaNumberSystems {
    public static void main(String[] args) {
        // 1. Defining literals in source code
        int decimalValue = 42;
        int binaryValue = 0b101010; // 42 expressed in binary
        int octalValue = 052;       // 42 expressed in octal
        int hexValue = 0x2A;        // 42 expressed in hexadecimal

        System.out.println("Literal values evaluate identically in Java:");
        System.out.println("Binary 0b101010 = " + binaryValue);
        System.out.println("Hex 0x2A = " + hexValue);

        // 2. Converting Decimal Integers to String representations
        int number = 255;
        String binStr = Integer.toBinaryString(number); // "11111111"
        String octStr = Integer.toOctalString(number);  // "377"
        String hexStr = Integer.toHexString(number);    // "ff"

        System.out.println("\nFormatted string outputs for 255:");
        System.out.println("Binary string: " + binStr);
        System.out.println("Octal string: " + octStr);
        System.out.println("Hex string: " + hexStr.toUpperCase());

        // 3. Parsing Strings in arbitrary bases back to decimal integers
        int parsedBin = Integer.parseInt("110101", 2);  // Parse Base 2
        int parsedOct = Integer.parseInt("346", 8);     // Parse Base 8
        int parsedHex = Integer.parseInt("2F8", 16);    // Parse Base 16

        System.out.println("\nParsed Values:");
        System.out.println("Parsed binary 110101: " + parsedBin);
        System.out.println("Parsed hex 2F8: " + parsedHex);
    }
}
```

## Common Mistakes Beginners Make

When working with number systems for the first time, beginners often encounter several predictable pitfalls. Keeping these in mind will save you hours of debugging time.

### 1\. Using Invalid Digits for a Given Base

A common error is including a digit that is outside the range permitted by the base.

*   *Error*: Writing \\(1021_2\\) as a binary number (the digit \\(2\\) is invalid in base 2).
    
*   *Error*: Writing \\(781_8\\) as an octal number (the digit \\(8\\) is invalid in base 8).
    

### 2\. Grouping Bit Clusters from the Wrong Direction

When grouping binary digits into 3-bit (octal) or 4-bit (hex) blocks, **always group from right to left** (starting at the LSB). Grouping from left to right alters the value completely.

*Correct grouping of* \\(11011_2\\) *into hex (4 bits)*:

$$\text{Right to Left: } (0001)(1011) \implies 1\text{B}_{16} \quad \checkmark$$

 $$ \text{Left to Right: } (1101)(1000) \implies \text{D}8_{16} \quad \mathbf{X}$$

### 3\. Forgetting Hexadecimal Characters A through F

Remembering that hexadecimal digits extend past \\(9\\) to include letters (\\(\text{A}=10, \text{B}=11, \text{C}=12, \text{D}=13, \text{E}=14, \text{F}=15\\)) is critical.

*   *Mistake*: Writing \\(10\\) instead of \\(\text{A}\\) when doing remainder division by 16. The remainder sequence \\(10, 11\\) written side-by-side as `1011` will be misread as four separate digits instead of two hex digits `AB`.
    

### 4\. Stripping Leading Zeros Prematurely

While leading zeros on a standalone integer do not change its value (\\(00010_2 = 10_2\\)), stripping leading zeros during intermediate multi-step conversions causes major errors.

For instance, when converting the hex value `0x803` to binary, \\(0_{16}\\) must expand into four full zeros (`0000`). If you compress it to a single `0`, the whole binary alignment is ruined.

### 5\. Confusing String "10" with Value 10

Always double check whether you are working with the decimal value \\(10\\) or the string `"10"` in a non-decimal base. The string `"10"` in binary means \\(2_{10}\\), in octal it means \\(8_{10}\\), and in hex it means \\(16_{10}\\).

## Quick Cheat Sheet

Here is a quick summary table for fast reference during coding or exams.

<table style="min-width: 125px;"><colgroup><col style="min-width: 25px;"><col style="min-width: 25px;"><col style="min-width: 25px;"><col style="min-width: 25px;"><col style="min-width: 25px;"></colgroup><tbody><tr><td colspan="1" rowspan="1"><p><strong>Base Name</strong></p></td><td colspan="1" rowspan="1"><p><strong>Base Number</strong></p></td><td colspan="1" rowspan="1"><p><strong>Allowed Digits</strong></p></td><td colspan="1" rowspan="1"><p><strong>Bit Grouping Size</strong></p></td><td colspan="1" rowspan="1"><p><strong>Direct Shortcut</strong></p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>Binary</strong></p></td><td colspan="1" rowspan="1"><p>2</p></td><td colspan="1" rowspan="1"><p>0, 1</p></td><td colspan="1" rowspan="1"><p>1 bit</p></td><td colspan="1" rowspan="1"><p>Base system for logic circuits</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>Octal</strong></p></td><td colspan="1" rowspan="1"><p>8</p></td><td colspan="1" rowspan="1"><p>0 to 7</p></td><td colspan="1" rowspan="1"><p>3 bits (<latex-inline-node data-content="2^3 = 8">2^3 = 8</latex-inline-node>)</p></td><td colspan="1" rowspan="1"><p>Replace 1 octal digit with 3 bits</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>Decimal</strong></p></td><td colspan="1" rowspan="1"><p>10</p></td><td colspan="1" rowspan="1"><p>0 to 9</p></td><td colspan="1" rowspan="1"><p>N/A</p></td><td colspan="1" rowspan="1"><p>Human standard</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>Hexadecimal</strong></p></td><td colspan="1" rowspan="1"><p>16</p></td><td colspan="1" rowspan="1"><p>0-9, A-F</p></td><td colspan="1" rowspan="1"><p>4 bits (<latex-inline-node data-content="2^4 = 16">2^4 = 16</latex-inline-node>)</p></td><td colspan="1" rowspan="1"><p>Replace 1 hex digit with 4 bits</p></td></tr></tbody></table>

### Conversion Strategy Summary

*   **Decimal → Any Base**: Repeatedly divide by the target base, track remainders, and read bottom-to-top.
    
*   **Any Base → Decimal**: Multiply each digit by \\(Base^{position}\\) and sum the results.
    
*   **Binary ↔ Octal**: Group/expand bits in sets of 3.
    
*   **Binary ↔ Hexadecimal**: Group/expand bits in sets of 4.
    
*   **Octal ↔ Hexadecimal**: Convert through Binary first.
    

## Final Summary

We have covered a lot of ground in this guide. Let us do a quick recap of the foundational concepts you have learned:

1.  **Number systems rely on positional notation**. The place value of any digit is determined by its position multiplied by powers of the system's base.
    
2.  **Computers run on Binary (Base 2)** because electronic switches built out of silicon transistors operate most reliably in two discrete voltage states: ON (\\(1\\)) and OFF (\\(0\\)).
    
3.  **Octal (Base 8) and Hexadecimal (Base 16) exist as human shorthand**. Because \\(8\\) and \\(16\\) are powers of \\(2\\) (\\(2^3\\) and \\(2^4\\)), you can convert between binary bits and octal/hex digits visually without doing long division.
    
4.  **Conversions rely on simple rules**:
    
    *   To convert from Decimal to another base, use **repeated division**.
        
    *   To convert from another base to Decimal, sum up the **positional weights**.
        
    *   To convert between Octal and Hexadecimal, use **Binary as a bridge**.
        

Every high level language, framework, database, and operating system you will work with throughout your software development career rests on these simple base-level principles. When you feel comfortable reading, manipulating, and converting between different bases, low level computing stops feeling like mysterious magic and starts feeling like an approachable, logical system.

Keep practicing, build out the code exercises, and happy coding!
