CIS-261 Home http://www.c-jump.com/bcc/c261c/CIS261syllabus.html

Bits, Numbers, and Binary Data Representation


  1. Chapter 2, Bits, Data Types, and Operations
  2. Bit is a code
  3. Data Types
  4. Integer data types - unsigned integers
  5. Signed Integers
  6. Signed Magnitude Data Types
  7. 1's complement integers
  8. 2's complement integers
  9. Computing 2's complement example
  10. Addition of two 2's complement integers
  11. Binary to Decimal Conversion
  12. Decimal to Binary Conversion
  13. Decimal to Binary Conversion Summary
  14. Negation
  15. Subtraction of two 2's complement integers
  16. Sign Extension
  17. Overflow Condition
  18. Logical Operations
  19. AND Operation
  20. OR Operation
  21. NOT operation
  22. Exclusive OR operation, XOR
  23. Binary Masks
  24. Floating point data type
  25. ASCII codes
  26. Hexadecimal Notation

1. Chapter 2, Bits, Data Types, and Operations


  • Addition, multiplication, and their combinations

  •   addition, multiplication, and their combination

2. Bit is a code


3. Data Types


4. Integer data types - unsigned integers


5. Signed Integers


6. Signed Magnitude Data Types


  • Leftmost position represents a negative sign when set equal to 1.

  • The remaining bits in the number indicate the magnitude (or absolute value).

  • A consequence of this representation is that there are two ways to represent zero:

    • 00000000 (0) and

    • 10000000 (-0).

  • Unfortunately, this type of encoding would require a cumbersome hardware to do arithmetic addition.

  •  

    8 bit signed magnitude:
    Binary value Signed magnitude interpretation Unsigned interpretation
    00000000 0 0
    00000001 1 1
    ... ... ...
    01111111 127 127
    10000000 -0 128
    ... ... ...
    11111111 -127 255

7. 1's complement integers


  • Quite simple idea: to represent negative number,

    1. Take positive number,

    2. Set leftmost bit equal to 1.

    3. Flip the bits of positive number.

  • For example,

      5 = 0000 0101
     -5 = 1111 1010
    
  • Unfortunately, this too requires cumbersome hardware to do further addition.

  • 8 bit ones' complement:

    Binary value Ones' complement interpretation Unsigned interpretation
    00000000 0 0
    00000001 1 1
    ... ... ...
    01111101 125 125
    01111110 126 126
    01111111 127 127
    10000000 -127 128
    10000001 -126 129
    10000010 -125 130
    ... ... ...
    11111110 -1 254
    11111111 -0 255

8. 2's complement integers


  • Positive integers are represented in a straightfoward positional scheme.

  • Corresponding negative integer binary representations are calculated by the following steps:

    1. Invert each bit of the positive number.

    2. Add 1.

    3. If there is a carry over from the highest bit, ignore it.

  • The same steps are used to go from negative back to positive number.

  • 8 bit two's complement:

    Binary value Two's complement interpretation Unsigned interpretation
    00000000 0 0
    00000001 1 1
    ... ... ...
    01111110 126 126
    01111111 127 127
    10000000 -128 128
    10000001 -127 129
    10000010 -126 130
    ... ... ...
    11111110 -2 254
    11111111 -1 255

9. Computing 2's complement example

  • To obtain 2's complement representation of decimal -13 (negative thirteen)

    1. Take representation of positive 13:

      • 01101

    2. Compute complement by flipping each bit:

      • 10010

    3. Add 1:

      • 10011 (decimal -13)

  • To go back from -13 to positive 13, execute the same exact steps:

    1. Take representation of negative 13:

      • 10011

    2. Invert each bit:

      • 01100

    3. Add 1:

      • 01101 (decimal 13)

10. Addition of two 2's complement integers


11. Binary to Decimal Conversion


12. Decimal to Binary Conversion


  1. 105 a positive, odd number.

     

  2. Our task is to find values of bits a7 through a0 as follows:

  3. a7 is zero, because 105 is positive:

        position: 76543210
           value: 0???????
    

     

  4. a0 is one, because 105 is odd:

        position: 76543210
           value: 0??????1
    

     

  5. Subtracting one from 105 yields 104:

  6. Dividing both sides of the equation by 2 yields

  7. Since 52 is even, so a1 equals to zero:

        position: 76543210
           value: 0?????01
    

     

  8. Next, we can iterate back to

  9. Dividing both sides by 2 yields

  10. Subtracting one from both sides yields

  11. Dividing both sides by 2 yields

  12. Dividing both sides by 2 yields

  13. And, finally,

13. Decimal to Binary Conversion Summary


14. Negation


15. Subtraction of two 2's complement integers


16. Sign Extension


17. Overflow Condition



18. Logical Operations


19. AND Operation


  • AND is a binary logical function.

  • Similar to addition and subtraction, AND requires two operands.

  • Behavior of logical operation can be conveniently described by the truth table.

  • The operation is applied to individual bits at their respective positions.

  • The bit-wise AND operation can be described as follows:

     

    A B AND(A,B)
    0 0 0
    0 1 0
    1 0 0
    1 1 1

20. OR Operation


21. NOT operation


  • NOT is unary function and requires only one operand.

  • It is also known as a complement operation.

  • The output is formed by inverting the input bit-by-bit:

     

    A NOT(A)
    0 1
    1 0

22. Exclusive OR operation, XOR


  • XOR is a binary logical function.

  • XOR output is 1 if the values of input bits are different, that is, if values of input bits are not equal.

  • The output is zero, it two operands are the same.

  • XOR yields all zeroes, if input patterns are identical.

  •  

    A B XOR(A,B)
    0 0 0
    0 1 1
    1 0 1
    1 1 0

23. Binary Masks


24. Floating point data type


25. ASCII codes


26. Hexadecimal Notation


  • Simplifies notation of bit patterns.

  • Much better alternative, compared to binary number notation.

  • Simplifies notation of long binary strings, such as entire blocks of computer memory.

  • Hexadecimal notation is used mainly for human convinience.

  • Hexadecimal notation represents numbers
    of base 16, calculated as

    • h3*163 + h2*162 + h1*161 + h0*160

    where h3, h2, h1, and h0 are values from the Hexadecimal column of the table.

  •  

    Decimal Hexadecimal Octal Binary
    0
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    0
    1
    2
    3
    4
    5
    6
    7
    8
    9
    A
    B
    C
    D
    E
    F
    000
    001
    002
    003
    004
    005
    006
    007
    010
    011
    012
    013
    014
    015
    016
    017
    0000
    0001
    0010
    0011
    0100
    0101
    0110
    0111
    1000
    1001
    1010
    1011
    1100
    1101
    1110
    1111