• Home
    Stuff

    Welcome to our page, Madam Amni! :)

    Done by; Iman Sofea, Fatin Adira, Beh Soo Yuan, Hidayah, Dorothea & Nadiah Nazira.
Chapter 2: Data Representation


ABOUT DATA REPRESENTATION 


Computers use 0 and 1 to represent all kinds of data. It can be classified into these categories:
▲ Numbers used in arithmetic computation
▲ Letters of the alphabet used in the data
▲ Other discrete symbols used for specific purposes

ALPHANUMERIC REPRESENTATION

An alphanumeric character set is a set of elements that includes the 10 decimal digits, the 26 letters of the alphabet and a number of a special character such as $, + and =.
We have two types of alphanumeric ASCII code and EBCDIC code.
ASCII CODE 
EBCDIC CODE
NUMBER BASE

There are four types of bases Decimal (base 10), Binary (base 2), Octal (base 8) and Hexadecimal (base 16).


Decimal (base 10)

The base 10 number system uses the digits: 0,1, 2, 3, 4, 5, 6, 7, 8, and 9.





The decimal system is said to have a base or radix of 10. This means that each digit in the number is multiplied  by 10 raised to a power corresponding to that digit's position.

For example:

79 = ( 7 * 10^1 ) + ( 9 * 10^0 )

2394 = ( 2 * 10^3 ) + ( 3 * 10^2 ) + ( 9 * 10^1 ) + ( 4 * 10^0 )

The same principle holds for decimal fractions, but negative powers of 10 are used.
A number with both an integer and fractional part has digits raised to both positive and negative powers of 10.

For example:

442.256 = ( 4 * 10^2 ) + ( 4 * 10^1 ) + ( 2 * 10^0 ) + ( 2 * 10^-1 ) + ( 5 * 10^-2 ) + ( 6 * 10^-3)

Most significant digit
- The leftmost digit ( carries the highest value )

Least significant digit
- The rightmost digit

* THE SAME METHOD IS USE TO ARRIVE TO THE RESPECTIVE BASE.


Example for binary to decimal:





1010001112 = ( 1 * 2^8 ) + ( 0 * 2^7 ) + ( 1 * 2^6 ) + ( 0 * 2^5 ) + ( 0 * 2^4 ) + ( 0 * 2^3 ) + ( 1 * 2^2 ) + ( 1 * 2^1 )       

                      + ( 1 * 2^0 )

                  = 256 + 0 + 64 + 0 + 0 + 0 + 4 + 2 + 1
                  = 32710

Example for octal to decimal:

1228 = ( 1 * 8^2 ) + ( 2 * 8^1 ) + ( 2 * 8^0 )
        = 64 + 16 + 2
        = 8210

Example for hexadecimal to decimal:
1A16 = ( 1 * 16^1 ) + ( A * 16^0 )
         = ( 1 * 16^1 ) + ( 10 * 16^0 )
         = 16 + 10
         = 2610

* TO DETERMINE WHY A IS EQUAL TO 10 PLEASE REFER TO HEXADECIMAL NOTES. 

Binary ( base 2 )

Only use two digits which are 1 and 0.
To translate 19.687510 to the binary representation, the procedure is to separately consider the digits to the left of the decimal point and those to the right of the decimal point.

Let us consider the number 19. Divide the binary number by 2 and consider the remainder which is either 1 or 0.

For example:

19.687510

   - 19/2 = 9, remainder 1 least significant digit
   -  9/2  = 4, remainder 1
   -  4/2  = 2, remainder 0                                        READ FROM BOTTOM TO UPWARDS
   -  2/2  = 1, remainder 0
   -  1/2  = 0, remainder 1 most significant digit
   -  End of operation

        The final number is therefore 10011. 

19.687510

   - 0.6875 x 2 = 1.3750 - 1 ( most significant digit after decimal point )
   - 0.3750 x 2 = 0.7500 - 0
   - 0.7500 x 2 = 1.5000 - 1                                     READ FROM UP TO DOWNWARDS
   - 0.5000 x 2 = 1.0000 - 1 

19.687510 = 10011.10112

Octal ( base 8 )

Base 8 uses the digits 0, 1, 2, 3, 4, 5, 6 and 7

To convert decimal to octal:






Answer: 20048



To convert a binary number you should be grouped into 3 numbers.
You can refer to below equation to further understand the working.




Example binary to octal notation.

Given: 1111101.10012

001   111   101   .   100   100
 1        7      5    .     4       4

= 175.448

Example octal to binary notation.

Given: 56.38

  5      6    .    3
101   110     001

= 101110.0012


Hexadecimal ( base 16 )

The hexadecimal number system uses the following digits:

0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F

Binary digits are grouped into sets of 4 bits, called a nibble.
Each possible combination of four binary digits is given a symbol, as follows:

0000 = 0   0100 = 4   1000 = 8   1100 = C
0001 = 1   0101 = 5   1001 = 9   1101 = D
0010 = 2   0110 = 6   1010 = A   1110 = E
0011 = 3   0111 = 7   1011 = B   1111 = F

Because 16 symbols are used, the notation is called hexadecimal and the 16 symbols are the hexadecimal digits.

DECIMAL, BINARY AND HEXADECIMAL TABLE.

Converting decimal to hexadecimal:

26 ÷ 16 = 1 with A left over
1 ÷ 16 = 0 with 1 left over

Answer: 2610 = 1A16.

Converting binary to hexadecimal:

To convert hexadecimal to binary, simply reverse the process by converting each hexadecimal digit. For example, to convert 7B to binary, begin by breaking the number apart: List each digit, namely 7 and B and then convert:

7= 0111   B = 1011

Then list the numbers from left to right, namely 0111 1011.

Example given: 101110.01102 

0010   1110   .   0110
   2        E           6

Answer : 2E.616    

* PLEASE REFER THE FOUR BINARY DIGITS GIVEN ABOVE 



Converting hexadecimal to binary:

Example given: 1A.816   

  1         A   .    8
0001   1010 .  1000

Answer: 00011010.10002   


Converting octal to hexadecimal:

example given: 23.478

In this case there are two steps to be followed:
- 1st step convert octal to binary    
  
      2      3    .    4     7
     010  011  .  100  111

= 010011.1001112  

- 2nd step binary to hexadecimal      

    0001  0011  .  1001   1100    
      1        3     .   9         C     

Answer : 13.9C16



Converting hexadecimal to octal:

example given: 26B.5D16

     2        6       B     .     5       D
   0010  0110  1011   .  0101  1101

= 001001101011.010111012

  001   001   101   011   .   010    111   010
   1       1      5       3     .     2        7      2

Answer : 1153.2728




BINARY REPRESENTATIONS

Binary numbers can be stored in 2 different formats.
  - unsigned numbers
  - signed numbers ( signed magnitude, one's complement, two's complement )



Sign-magnitude representation

Assign the leftmost ( most significant ) bit to the sign bit.

If the sign bit is 0: positive                  eg: +18 = 00010010
If the sign bit is 1: negative                       - 18 = 10010010

The remaining bits are used to represent the magnitude of the binary number in the unsigned binary notation.


Two representations of zero  ( +0 and -0 )
- cause complication for computers checking numbers for equality.

Need to consider both sign and magnitude in arithmetic.

For performing addition and subtraction, we required a special consideration of both sign of the numbers to properly compute of the operation.

Two's complement

Decimal -> 2's complement

1. If A is positive, represent it using the sign-magnitude representation. The leftmost bit must be 0, and the     remaining bits are the binary for the integer. Be careful there are enough bits available to represent the number.

2. If A negative, first represent in binary +A.
  a. Flip all the 1's to 0's and the 0's to 1's.
  b. Add 1 to the result using unsigned binary notation.

For example:

What is -5 in two's complement?

          5 = 0101
  
         1010 ( 1's complement of 0101 )
       +     1
        ---------
         1011 ( 2's complement of 0101 )
        ---------


2's complement -> decimal
1. If the leftmost bits is 0, the number is positive. Compute the magnitude as an unsigned binary number.

2. If the leftmost bits is 1, the number is negative. 
   a. Flip all the 1's to 0's, and the 0's to 1's.
   b. Add 1 to the result using unsigned binary notation.
   c. Compute the value as if it were an unsigned binary value, say it is B. This is the magnitude of the negative number.
   d. The actual value is -B.

For example:




What is the decimal value of the twos complement binary value 11100?
                       
                       Leftmost 1=-ve, 
                       Complement / flip=00011
                       Add 1=00100
                       Compute the value=4
                       Ans=-4

        11100

        00011 --> flip

        00011
      +       1
       ----------
        00100
       ---------- 

      = 4
    Answer : -4

Benefit of two's complement


- One representation of zero
- Arithmetic works easily 
- Negating is fairly easiy

     eg: 3 = 00000011
         Boolean complement gives 
                11111100
         Add 1 to lSB
                11111101












Addition and subtraction for the Signed binary numbers in 2's complement




-Normal binary addition

-Monitor sign bit for overflow

-Take twos compliment of subtrahend and add to minuend

i.e. a - b = a + (-b)



-So we only need addition and complement circuits

Addition

0 + 0 = 0
1 + 0 = 1
1 + 1 = 0 [ carry of 1 to next column ( next more significant position to the left ) ]
1 + 1 + 1 = 1 [ carry of 1 to next column ( next more significant position to the left ) ]

For example:

     6 = 0110 --> flip

           1001
          +    1
          ---------
           1010
          ---------

     -610      1010           
     +710     0111
    --------   --------
       110    10001 = 0001
    --------   --------

Subtraction

1. Form 1's complement of B.
2. Add 1 to 1's complemet of B to form 2's complement.
3. Add 2's complement of B to A.
4. Check carry (CY) out of MSB and sign bit (MSB) of result.
       a. If CY = 1 and result is positive. The result is probably valid.
       b. If CY = 0 and result is negative. The result is probably valid.
Borrow =1

For example:

                 5 - 2











how to get 1110?

2= 0010 --> flip

     1101
    +    1
    --------
    1110
    --------

Normalized Floating-point

For example:

      110.111012

  Answer : 1.1011101 x 22

* if you move to the front it will become positive

      0.01011012
  Answer : 1.01101 x 2-2

* if you move to the back it will become negative

Underflows

• below the minimum number that can be represented.

• minimum number: is 2-127 in single precision.

An underflow condition is identified by setting all the bits in the exponent to zero and all bits in the mantissa to zero. Clearly in this case the number represented is 0. There are 2 types of underflow: +0 and -0, distinguished by the first bit in the word, i.e. the sign.

Overflow


• x is larger than the largest possible number that can be represented in a word.



• The exponent is simply set to its maximum value.

• while the mantissa is zero.

A NaN


• performs an illegal operation.



• Examples : 0/0, 1/1 etc.

results which are indeterminate.

represented within a computer word as an exponent of 255 and a nonzero mantissa. The sign can take either value. 










Prepared by IMAN SOFEA ZAKARIA
1121115830









Wednesday 1 May 2013 22:15 / 0 commentator(s) | Just click and you'll see. | Scroll up to top