Docstoc

AS binary

Document Sample
AS binary Powered By Docstoc
					AS105 – Data Representation in a Computer




Data Representation in a Computer - 1                                                            AS105
                                                                                                Module 1
Specification
AS Module 1             10.1 - Fundamentals of Computer                  The generation of bit patterns
                        Systems                                          in a computer
                        10.3 - Fundamentals of Information               Number representation systems
                        & Data Representation                            Information Coding Systems

References
A Level Computing 4th Ed.            Chapter 3                              Pages 12 to 15
                                     Chapter 16                             Pages 74 to 77


1. Introduction
Computers can process data in the form of binary numbers only. This unit introduces you
to the reasons for this and how data such as text and decimal numbers are represented and
stored inside a computer.

2. What is the Binary Number system?
You will be well used to working in the decimal number system for all your calculations
and number problems.

1)       What are the digits that you use in the decimal system?



2)       How many possible values can a decimal digit in a number have?



Each digit in the binary number system can only have one of two possible values namely
1 or 0.

Binary arithmetic is called Base 2 arithmetic; decimal (denary) is called Base 10. In
denary we count in tens while in binary we count in twos.

Counting in:
Denary   0     1   2      3    4      5     6     7     8         9      10     11     12     13     14     15
Binary   0     1   10     11   100    101   110   111   1000      1001   1010   1011   1100   1101   1110   1111


Computers use the binary system because the electronic circuits inside the CPU are made
up of millions of microscopic electronic switches. A switch can be used to represent one
binary digit. 0 is represented by the switch being OFF and 1 by the switch being ON.
For example a light switch is an example of a simple binary device in that it can have two
states (or values) ON or OFF (1 or 0).

Data and computer instructions (programs) are represented in the computer in the form of
binary numbers. For example the number 25 might be stored as the binary equivalent


                                             R. A. Naylor 2002                                             1
AS105 – Data Representation in a Computer


00011001 and the letter 'A' as 01000001. In other words data is held in the form of
binary code numbers. Different binary code systems are used for different types of data
such as decimal numbers, text, pictures, video and sound. The main point is that all data
is held inside a computer as a sequence of binary numbers.

3. Bits, Bytes and Words

Bit     A binary digit - i.e. 0 or 1.

Byte A group of bits required to hold the code of one character - usually 8 bits so the
letter 'A' is stored as 01000001. The size of computer memory and storage devices is
measured in bytes.

Word A group of one or more bytes that the computer's processor can process
simultaneously.

For example:
        Processor                       Word length               No of bits processed in one go
8 bit computer                             1 byte                                8
16 bit computer                            2 bytes                              16
32 bit computer                            4 bytes                              32
64 bit computer                            8 bytes                              64

A Pentium computer has a 64-bit processor.

4. Number Bases
As you might imagine binary numbers could get very long and, consequently, are very
easy to write down wrongly. Computer programmers and engineers tend to work in the
Hexadecimal system (base 16 number system) which is easier to write down and which is
also easily converted into binary.

        Number System                   Base           Digits used
        BINARY                          2              0,1
        DECIMAL                         10             0,1,2,3,4,5,6,7,8,9
        HEXADECIMAL                     16             0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F

5. Place Value
Each digit in a number has a value associated with its place in the number.

       Denary                    103         102          101     100
                                1000         100           10       1 place value
       Base 10 no.                 7           6            3       7

       Binary                      23           22          21     20
                                    8            4           2      1 place value
       Base 2 no.                   1            1           0      1




2                                            R. A. Naylor 2002
AS105 – Data Representation in a Computer




       Hexadecimal               163         162          161          160
                                4096         256           16            1 place value
       Base 16 no.                 B           2            3            F

6. Simple Conversions
The use of place value makes conversion of binary and hexadecimal numbers to denary
(decimal) very easy.

Convert 1101 to denary (decimal):
Place value 8        4      2     1
              1      1      0     1
       so     8x1+ 4x1+ 2x0+ 1x1                     =            13

Convert B23F to denary:
Place value 4096 256     16    1
             B      2    3     F
       so    4096x11+256x2+16x3+1x15 =                            45,631

3)      Convert the following numbers into decimal:
        (i) 11112      (ii) 101012  (iii) 110011002




        (iv) 1216       (v) E216            (vi) ABC16




Converting decimal to binary or hexadecimal is also straight forward.

Convert 56 to binary:
Divide by 2 and write down the remainder.

                                                         Remainders
                                    2       56           0
                                    2       28           0
                                    2       14           0
                                    2        7           1
                                    2        3           1
                                    2        1           1
                                             0

        Answer:         01110002




                                             R. A. Naylor 2002                          3
AS105 – Data Representation in a Computer


Convert 200 to hexadecimal:
Divide by 16 and write down the remainder.

                                                         Remainders
                                  16 200                 8
                                  16 12                  12 (C)
                                       0

        Answer:         C816

4) Convert the following decimal numbers into binary and hexadecimal.
       (i) 67




        (ii) 25




        (iii) 127




7. Representing Numbers
(a) Simple Binary
Simple binary can only be used to represent positive whole numbers (positive integers).
The range of the numbers depends on the number of bits used. Thus an 8 bit binary
number can have any whole number in the range 0 to 255:

        00000000        =       0
        11111111        =       255

That is an 8 bit binary number can have 256 possible values (the same as 28 or
2x2x2x2x2x2x2x2)

5) How many numbers can a 4 bit binary number code represent?




4                                            R. A. Naylor 2002
AS105 – Data Representation in a Computer


(b) Sign & Magnitude Code
Both positive and negative integers can be catered for by representing the sign (+ or -)
and the magnitude of the number separately.

Usually the sign bit uses 0 for + and 1 for - and is placed at the left-hand end of the
number.
       001001          =       9
       101001          =       -9
       110000          =       -16

6) Using 6 bit sign and magnitude code, code the following numbers:
       -7, +30, -29




7) What range of integers can be coded using 6 bit sign and magnitude code?




(c) Two’s Complement Code
This is a slightly different method of coding integers and is more common in computers
because of its usefulness in performing calculations in the processor. Normal binary
place values are used except that the left hand bit (the most significant bit) has a negative
value.

Some 6 bit 2’s complement numbers:
       -32     16      8     4     2       1
       0       1       1     1     1       1=             31
       0       0       0     0     0       1=             1
       1       1       1     1     1       1=-32+31       -1
       1       0       0     0     0       0=-32+0        -32
Thus, using 6 bit 2’s complement number in the range -32 to +31

7) Using 6 bit 2’s complement code convert the following numbers:
       (i) 22, (ii) -30, (iii)-25, (iv) 19




                                             R. A. Naylor 2002                             5
AS105 – Data Representation in a Computer


(d) Fractions
Just as you can have decimal fractions and a decimal point so you can have binary
fractions and a binary point
        125.678               11101.1101
Such numbers are represented by a more complicated use of 2’s complement.


8. Representing Characters
Just as numbers need to be represented by a binary code so do characters. Whenever you
type a character at the keyboard it is turned into a binary number before going to the
computer. The most common coding system for characters is ASCII the American
Standard Code for Information Interchange. The ASCII code uses a 7-bit code so we can
have 27 or 128 possible codes. Because a single memory cell in a computer can hold an
8-bit number modern computers use character codes based on the ASCII code but using 8
bits.

See Chapter 3 page 13 for a full list of ASCII codes.

8) How many characters can be coded using an 8-bit code?



The extra codes are used for special characters for line drawing or foreign alphabets (e.g.
Greek).
       00100001       A       (65)
       00100010       B       (66)
       00100111       C       (67)

The codes between 0 and 31 are special codes (control codes) which can be used to
control devices receiving or generating the characters. For example code 7 would cause a
bell or buzzer to sound on a printer.

EBCDIC (Extended Binary Coded Decimal Interchange Code) is an alternative character
coding system used mainly in mainframe computers. This is a full 8-bit code. Some
example codes are:

 Char    EBCDIC         Char    EBCDIC              Char      EBCDIC     Char   EBCDIC
  0      11110000        A      11000001             K        11010010    U     11100100
  1      11110001        B      11000010             L        11010011    V     11100101
  2      11110010        C      11000011             M        11010100    W     11100110
  3      11110011        D      11000100             N        11010101    X     11100111
  4      11110100        E      11000101             O        11010110    Y     11101000
  5      11110101        F      11000110             P        11010111    Z     11101001
  6      11110110        G      11000111             Q        11011000
  7      11110111        H      11001000             R        11011001
  8      11111000        I      11001001             S        11100010
  9      11111001        J      11010001             T        11100011

UNICODE is an international 16-bit code (therefore 28 or 65536 codes) which is
sufficient to represent all the characters in any language or script.




6                                            R. A. Naylor 2002
AS105 – Data Representation in a Computer



AS105 - Revision Questions
1) Write down all the:
   i. decimal digits

    ii. hexadecimal digits

    iii. binary digits


2) Give another name for a binary digit


3) What is a byte?


4) Convert the following decimal numbers to binary:
    i. 29

    ii. 57

    iii. 12

    iv. 126


5) Convert the following decimal numbers to hexadecimal:
    i. 89

    ii. 57

    iii. 312

    iv. 126


6) Convert the following to decimal:
    i. AA16

    ii. 23F16

    iii. 10101112

    iv. 1110001112


7) Convert the following into binary:
    i. AA16




                                             R. A. Naylor 2002   7
AS105 – Data Representation in a Computer


    ii. 23F16


8) Convert the following into hexadecimal:
    i. 101111

    ii. 111000111


9) Convert the following into 6-bit sign & magnitude code
    i. 25

    ii. 17

    iii. –30

    iv. –3


10 Convert the following into 6 bit 2's complement code:
   i. 25

    ii. 17

    iii. –30

    iv. –3

11) Using 7 bit 2's complement code what is:
    i. the largest positive number (give binary and decimal forms)

    ii. the largest negative number(give binary and decimal forms)

    iii. the range of possible integers (in decimal)


12) Why is it necessary to use binary representations of data in a computer?


13) What does ASCII stand for?


14) Give an example of an ASCII control code?


15) ASCII is a 7-bit code - how many possible codes does this allow?


16) A computer memory location normally holds 8 bits (1 byte). Give two uses of the
extra bit when added to the 7-bit ASCII code.



8                                            R. A. Naylor 2002

				
DOCUMENT INFO
Shared By:
Categories:
Stats:
views:28
posted:4/4/2011
language:English
pages:8