Binary Octal and HexaDecimal Numbers


As humans, we generally count and perform arithmetic using the decimal, or base 10, number system. The base of a number system is simply the number of different digits, including zero, that exist in the number system. In any particular set of circumstances, a particular base might be chosen for convenience, efficiency, technological, or any other reasons. Historically, it seems that the main reason that we use base 10 is that humans have ten fingers, which is as good a reason as any.

Any number can be represented equivalently in any base, and it is always possible to convert a number from one base to another without changing its meaning.

Computers perform all of their operations using the binary, or base 2, number system. All program code and data are stored and manipulated in binary form.Calculations are performed using binary arithmetic. Each digit in a binary number is known as a bit (for binary digit) and can have only one of two values, 0 or 1. Bits are commonly stored and manipulated in groups of 8 (known as a byte), 16 (usually known as a halfword), 32 (a word), or 64 bits (a doubleword). Sometimes other groupings are used.

The number of bits used in calculations affects the accuracy and size limitations of numbers manipulated by the computer. And, in fact, in some programming languages, the number of bits used can actually be specified by the programmer in declaration statements.(C.C+,Java) 

The knowledge of the size limits for calculations in a particular language is sometimes extremely important, since some calculations can cause a numerical result that falls outside the range provided for the number of bits used. In some cases this will produce erroneous results, without warning to the end user of the program.It is useful to understand how the binary number system is used within the computer. Often, it is necessary to read numbers in the computer in their binary or equivalent hexadecimal form.

1. Numbers

Numbers are typically represented in binary format by converting each digit to binary equivalents.

  • Example: Representing the decimal number 5 in binary.

    • 5 in decimal is 101 in binary.
  • Example: Representing 10 in binary.

    • 10 in decimal is 1010 in binary.

2. Text (Characters)

Text characters are represented using standardized encoding schemes, like ASCII (American Standard Code for Information Interchange) or Unicode.

  • Example: Representing the character 'A' in ASCII.

    • In ASCII, 'A' is represented by the decimal number 65.
    • 65 in binary is 01000001.
  • Example: Representing the character 'a'.

    • In ASCII, 'a' is represented by 97.
    • 97 in binary is 01100001.

3. Images

Images are represented in binary by breaking down each pixel into binary values that represent color information. In grayscale images, each pixel might be represented by an 8-bit binary number, while in color images (like RGB), each color channel (Red, Green, Blue) may use 8 bits, giving a total of 24 bits per pixel.

  • Example: A grayscale pixel with an intensity value of 200.

    • 200 in binary is 11001000.
  • Example: An RGB pixel with values (Red=255, Green=0, Blue=127).

    • Red: 11111111, Green: 00000000, Blue: 01111111.

4. Sound

Sound is represented as a sequence of binary values that correspond to sample amplitudes of the audio signal at each point in time. These samples are often stored as 8-bit, 16-bit, or 32-bit binary numbers.

  • Example: A sound sample with an amplitude of 128 in 8-bit audio.
    • 128 in binary is 10000000.

5. Instructions

Machine instructions are represented in binary and are specific to the processor. Each instruction consists of an "opcode" (operation code) and possibly some additional data (like an address or value).

  • Example: An imaginary instruction ADD R1, R2 (add the contents of register R2 to register R1).
    • This might be encoded in binary as something like 0001 0001 0010 (specific to the processor architecture).

These examples show how computers represent different data types in binary. The binary system enables efficient data storage and processing due to its compatibility with digital circuits

Converting between decimal and binary is a fundamental process in computer science. Let's go over each conversion method with examples.

1. Converting Decimal to Binary

To convert a decimal number to binary, repeatedly divide the number by 2, recording the remainder at each step. The binary number is formed by reading the remainders in reverse order (from bottom to top).

Steps:

  1. Divide the decimal number by 2.
  2. Record the remainder (0 or 1).
  3. Use the quotient (result of division) as the new number to divide by 2.
  4. Repeat until the quotient is 0.
  5. The binary number is the sequence of remainders read in reverse.

Example: Convert 25 to binary

  1. 25÷2=12 25 \div 2 = 12 with a remainder of 1.

  2. 12÷2=6 12 \div 2 = 6 with a remainder of 0.

  3. 6÷2=3 with a remainder of 0.

  4. 3÷2=1 with a remainder of 1.

  5. 1÷2=0 1 \div 2 = 0 with a remainder of 1.

    Reading the remainders from bottom to top, 25 in decimal is 11001 in binary.

Another Example converting decimal number 17 to binary



2. Converting Binary to Decimal

To convert a binary number to decimal, use the place value of each binary digit. Each binary place represents a power of 2, starting from 2^0 at the rightmost bit.

Steps:

  1. Write down the binary number.
  2. Starting from the right, multiply each binary digit by 2n2^n, where nn is the position of the digit from the right (starting at 0).
  3. Sum all the results to get the decimal equivalent.

Example: Convert 11001 to decimal

  1. Identify the position of each bit in 11001: 1,1,0,0,11, 1, 0, 0, 1.

  2. Multiply each bit by 22 raised to the power of its position:

    • 1×24=161 \times 2^4 = 16
    • 1×23=81 \times 2^3 = 8
    • 0×22=00 \times 2^2 = 0
    • 0×21=00 \times 2^1 = 0
    • 1×20=11 \times 2^0 = 1
  3. Sum the values: 16+8+0+0+1=2516 + 8 + 0 + 0 + 1 = 25

    So, 11001 in binary is 25 in decimal.

Another Example 


2. Octal (Base-8)

Octal uses eight digits: 0 through 7. It is useful as a shorthand representation of binary because each octal digit corresponds to exactly three binary bits.

  • Example:
    • Binary: 101011 can be grouped into three bits from the right as 000 101 011.
    • Octal: 000 is 0, 101 is 5, and 011 is 3, so the octal number is 053.
    • Decimal Equivalent: 0×82+5×81+3×80=0+40+3=430 \times 8^2 + 5 \times 8^1 + 3 \times 8^0 = 0 + 40 + 3 = 43

3. Hexadecimal (Base-16)

Hexadecimal uses sixteen symbols: 0 to 9 and A to F (where A represents 10, B represents 11, and so on up to F which represents 15). It’s another shorthand for binary, where each hex digit represents four binary bits.

  • Example:
    • Binary: 11011011 can be grouped into four bits from the right as 1101 1011.
    • Hexadecimal: 1101 is D, and 1011 is B, so the hexadecimal number is DB.
    • Decimal Equivalent: D×161+B×160=13×16+11=208+11=219D \times 16^1 + B \times 16^0 = 13 \times 16 + 11 = 208 + 11 = 219

Fractional Conversion Methods
The intuitive conversion methods previously discussed can be used with fractional numbers. The computational methods have to be modified somewhat to work with fractional numbers.

To convert fractional numbers from base 10 to another base, it is usually easier to use a variation on the division method shown earlier. Recall that for an integer, this involved dividing the number repeatedly by the base value and retaining the remainders. Effectively, this method works by shifting the radix point to the left one place each time we divide by the base value and noticing what drops over the radix point, which is the remainder. The number point is initially assumed to be to the right of the number.
When the value being converted is to the right of the number point, the procedure must work exactly the opposite. We multiply the fraction by the base value repeatedly, and record, then drop, the values that move to the left of the radix point. We repeat this procedure until the desired number of digits of accuracy is attained or until the value being multiplied is zero. Each time we multiply, we effectively expose the next digit.



Examples:

Convert 12.375 to Binary


🔹 Step 1: Convert the Integer Part (12)

Divide by 2 and record remainders:


12 ÷ 2 = 6 remainder = 0 6 ÷ 2 = 3 remainder = 0 3 ÷ 2 = 1 remainder = 1 1 ÷ 2 = 0 remainder = 1

Write remainders bottom to top:
12₁₀ = 1100₂


🔹 Step 2: Convert the Fractional Part (0.375)

Multiply by 2 and record the integer part of each result:


0.375 × 2 = 0.750 → integer part = 0 0.750 × 2 = 1.500 → integer part = 1 0.500 × 2 = 1.000 → integer part = 1

Stop when the fractional part becomes 0 (or after desired precision).

So:
0.375₁₀ = .011₂

Final Answer:

Combine both parts:

12.375₁₀ = 1100.011

Example: Convert 1011.101 (Binary) to Decimal

🔹 Step 1: Convert the Integer Part 1011₂

Break it down:

1 × 2³ = 8 0 × 2² = 0 1 × 2¹ = 2 1 × 2⁰ = 1

Sum = 8 + 0 + 2 + 1 = 11


🔹 Step 2: Convert the Fractional Part .101₂

1 × 2⁻¹ = 0.5 0 × 2⁻² = 0.0 1 × 2⁻³ = 0.125

Sum = 0.5 + 0.0 + 0.125 = 0.625

Final Answer:

1011.101 = 11.625₁₀


Example: Convert 1101011.101 (Binary) to Octal

🔹 Step 1: Group bits in threes

  • From the binary point, group left and right in 3s:

Integer part: 1 101 011 pad left: 001 101 011 Fractional part: 101 already 3 bits

🔹 Step 2: Convert each group to octal:

001 → 1 101 → 5 011 → 3 . 101 → 5

Final Answer:

1101011.101₂ = 153.5₈

Example: Convert 1101011.101 (Binary) to Hexadecimal

🔹 Step 1: Group bits in fours

  • From the binary point, group left and right in 4s:

Integer part: 1101011 pad left: 0110 1011 Fractional part: 101 pad right: 1010

So:

Integer part: 0110 1011 6 B Fractional part: 1010 A

Final Answer:

1101011.101₂ = 6B.A₁₆

Comments

Popular posts from this blog

Foundations Of Computing: From Hardware Essentials To Web Design GXEST203 2024 scheme Dr Binu V P

Computer Architecture

Memory Hierarchy