Data Representation and Binary Arithmetic

Data Representation and Binary Arithmetic Notes

Conversion Between Number Bases

  • Binary to Decimal Conversion:

    • Example: Convert binary value 10101 into decimal

    • Options:

      • a. 20

      • b. 22

      • c. 21

  • Decimal to Binary Conversion:

    • Example: Convert decimal 58 into binary

    • Options:

      • d. 111010

      • e. 101110

      • f. 111001

  • Hexadecimal Number System:

    • Definition: Hexadecimal is referred to as Base 16.

    • Options:

    • g. Base 2

    • h. Base 10

    • i. Base 16

  • Hexadecimal to Decimal Conversion:

    • Example: Convert hexadecimal 2A into decimal:

    • Calculation:

      • $2 \times 16^1 + 10 \times 16^0 = 32 + 10 = 42$

    • Result: 42

  • Decimal to Hexadecimal Conversion:

    • Example: Convert decimal 35 into hexadecimal:

    • Calculation:

      • $35 \div 16 = 2 \text{ remainder } 3$

    • Result: 23

Learning Outcomes

  • By the end of this lesson, students will be able to:

    • Add 2 binary numbers together.

    • Perform binary shifts on 8-bit binary numbers.

    • Complete various binary conversions.

Binary Addition

  • Addition of binary numbers follows specific rules:

    1. Work right to left when adding.

    2. Add the unit's place first and carry over if needed:

    • Example of simple decimal addition:

      • $1 + 1 = 10$ in binary, carries 1 to the next column.

Rules of Binary Addition
  • The following rules apply for binary addition:

    1. $0 + 0 = 0$

    2. $0 + 1 = 1$

    3. $1 + 0 = 1$

    4. $1 + 1 = 0$ (carry 1)

    5. $1 + 1 + 1 = 1$ (carry 1)

  • Example of binary addition demonstrating various cases:

    • Calculation:
      1011

    • 1010
      Result:

    • Carrying at bit positions leads to a final result of 10101.

Binary Shifts

  • Binary Shift Left:

    • Shifting bits to the left (L)

    • This operation doubles the value of the binary number.

    • Example:

      • 1000 = 8 (in decimal)

      • Shift left once results in 10000 = 16 (in decimal)

  • Binary Shift Right:

    • Shifting bits to the right reduces the binary value.

    • This operation halves the value of the binary number.

    • Example 1:

      • Start with 1000 = 8

      • Right shift once gives you 100 = 4

      • Right shift again gives you 10 = 2

    • Example 2:

      • Start with 1001 = 9

      • Right shift once gives you 100 = 4

      • Right shift again gives you 10 = 2

  • Logical Shift Operations:

    • Left shifts multiply a number by 2 for each shift;

    • Right shifts divide a number by 2.

    • Example: shifting 1110 yields values (in binary):

    • Left shift 1110 = 11100 (multiplies the number).

    • Right shift 1110 = 111 (divides the number).

  • Loss of Accuracy:

    • Important to note that shifts may result in loss of accuracy, especially where fractional values are represented.

    • Example: The value 22 / 4 is not exactly 5.

Worksheet Task and Exercises

  • Practical Exercises: Students will perform calculations and compare answers with a partner:

    1. Calculate: 1001 0101 + 0010 0110

    2. Add 0100 0011 to the result of the previous question.

    3. Calculate the left shift of 0110 1011.

    4. Explain the effect of a left shift on the binary value.