DATA REPRESENTATION IN A COMPUTER - Computer Studies Form 3 Notes

Share via Whatsapp
Download PDF for future reference Get on Whatsapp for 50/-

Introduction

  • Computers are classified according to functionality, physical size and purpose.
  • When classified according to functionality, computers can be analog, digital or hybrid.
  • Digital computers process data that is in discrete form while analog computers process data that is continuous in nature.
  • Hybrid computers, on the other hand can process both discrete and continuous data.
  • In digital computers, the user input is first converted and transmitted as electrical pulses that can be represented by two distinct digits' l' and '0' before processing.
  • These two digits are referred to as binary digits or in short bits.
  • Although two graphs can look different in their appearance, they may repeat themselves at equal time intervals.
  • Electronic signals or waveforms of this nature are said to be periodic.
  • Generally, a periodic wave representing a signal can be described using the following parameters.
    • Amplitude (A)
    • Frequency (f)
    • Periodic time (T)

Amplitude (A)

  • Amplitude is the maximum value a wave can attain.
  • For example, the amplitude of waves in Figure 1.1 is 1.

Frequency (f):

  • Frequency of a wave is the number of cycles made by the wave in one second.
  • It is measured in units called hertz (Hz).
  • 1Hz is equivalent to 1 cycle/second.

Periodic Time (T):

  • The time taken by a signal to complete one cycle is called periodic time.
  • Periodic time, T, is given by the formula T = 1/f where f is the frequency of the wave.
  • When a digital signal is to be sent over analog telephone lines e.g. e-mail, it has to be converted to analog signal.
  • This is done by connecting a device called a modem to the digital computer.
  • This process of converting a digital signal to an analog signal is known as modulation.
  • On the receiving end, the incoming analog signal is converted back to digital form in a process known as demodulation.

Concepts of Data representation in Digital Computers

  • Since digital computers are the most widely used, this notes seeks to explain in details how data is represented in digital form.
  • Data and instructions cannot be entered and processed directly into computers using human language.
  • Any type of data be it numbers, letters, special symbols, sound or pictures must first be converted into machine readable form i.e. binary form.
  • Due to this reason, it is important to understand how a computer together with its peripheral devices handle data in its electronic circuits, on magnetic media arid in optical devices.

Data Representation in Electronic Circuits

  • Electronics components, such as the microprocessor, are made up of millions of electronic circuits.
  • The availability of a high voltage (on) in these circuits is interpreted as 'I' while a low voltage (off) is interpreted as a '0'.
  • This concept can be compared to switching on and off of an electric circuit.
  • When the switch is closed, the high voltage in the circuit causes the bulb to light (' l' state).
  • On the other hand, when the switch is open, the bulb goes off ('0' state).

Data Representation on Magnetic Media

  • The presence of a magnetic field in one direction on magnetic media is interpreted as 'I', while the field in the opposite direction is interpreted as '0'.
  • Magnetic technology is mostly used on storage devices which are coated with special magnetic materials such as iron oxide.
  • Data is written on the media by arranging the magnetic dipoles of some iron oxide particles to face in the same direction and some others in the opposite direction.
  • The figure below shows how data is recorded on the surface of a magnetic disk. Note that the dipoles on the track are arranged in groups facing opposite directions.

    writing data to magnetic disk

Data Representation on Optical Media

  • In optical devices, the presence of light is interpreted as '1' while its absence is interpreted as '0'.
  • Optical devices use this technology to read or store data.
  • Take an example of a CD-ROM.
  • If the shiny surface is placed under a powerful microscope, the surface can be observed to have very tiny holes called pits.
  • The areas that do not have pits are called land.

    laser beam on cd rom
  • The laser beam reflects from the land which is interpreted as '1' while in Figure 1.5 (b) the laser beam enters a 'pit' and is not reflected.
  • This is interpreted as '0'.
  • The reflected pattern of light from the rotating disk falls on a receiving photoelectric detector that transforms the patterns into digital form.

Reason for Use of Binary System in Computers

  • It has proved difficult to develop devices that can understand or process natural language directly due to the complexity of natural languages.
  • It is, however, possible to develop devices that can understand binary language.
  • Devices that read, process and output data in digital form are used in computers and other digital devices such as calculators.
  • Binary logic has therefore simplified the technology needed to develop both hardware and software systems.
  • Other reasons for the use of binary are that digital devices are more reliable, small in size and use less energy as compared to analog devices.

Bits, Bytes, Nibble and Word

  • The terms bits, bytes, nibble and word are used widely in reference to computer memory and data size.
  • Let us explain each term.

Bits:

  • A bit can be defined as binary digits that can either be 0 or 1.
  • It is the basic unit of data or information in digital computers.

Byte:

  • A group of bits (often 8) used to represent a character is called a byte.
  • A byte is considered as the basic unit of measuring memory size in computers.

A Nibble:

  • Half a byte, which is usually a grouping of 4 bits is called a nibble.

Word

  • Two or more bytes make a word.
  • The term word length is used as a measure of the number of bits in each word.
  • For example a word can have a length of 16 bits, 32 bits, 64 bits etc.

Types of Data Representation

  • Computers not only process numbers, letters and special symbols but also complex types of data such as sound and pictures.
  • However these complex types of data take a lot of memory and processor time when coded in binary form.
  • This limitation necessitates the need to develop better ways of handling long streams of binary digits.
  • Higher number systems are used in computing to reduce these streams of binary into manageable form.
  • This helps to improve the processing speed and optimise memory usage.

Number Systems and their Representation

  • As far as computers are concerned, number systems can be classified into four major categories:
    • Decimal number system.
    • Binary number system
    • Octal number system.
    • Hexadecimal number systems.

Decimal Number System

  • The term decimal is derived from a Latin prefix deci which means ten.
  • Decimal number system has ten digits ranging from 0-9.
  • Because this system has ten digits, it is also called a base ten number system or denary number system,
  • A decimal number should always be written with a subscript 10 e.g. X1O
  • But since this is the most widely used number system in the world, the subscript is usually understood and ignored in written work.
  • However, when many number systems are considered together, the subscript must always be put so as to differentiate the number systems.
  • The magnitude of a number can be considered using three parameters.
    • Absolute value.
    • Place value or positional value.
    • Base value.
  • The absolute value is the magnitude of a digit in a number. For example, the digit 5 in 7458 has an absolute value of 5 according to its value in the number line.
  • The place value of a digit in an number refers to the position of the digit in that number i.e. whether "tens", "hundreds", "thousands" etc. as shown in the Table below.

     Thousands, 103  Hundreds, 102  Tens, 101  Ones, 10°
     7  4  5  8
  • The total value of a number is the sum of the place value of each digit making the number. For example, the total value of the digits can be worked out by as shown below:
    7 x 1000 = 7 000
    4 x 100 = 400
    5 x 10 = 50
    8 x 1 = 8
    Total = 7458
  • The base value of a number also known as the radix, depends on the type of number system that is being used. The value of any number depends on the radix. For example the number 10010 is not equivalent to 1002.

Binary Number System

  • Binary number system uses two digits namely, 1 and 0 to represent numbers.
  • Unlike in decimal numbers where the place values go up in factors of ten, in binary system, the place values increase by factors of two.
  • Binary numbers are written as X2.
  • Consider a binary number such as 10112.
  • The right most digit has a place value of 1 x 2° while the left most has a place value of 1 x 23 as shown.

     Place values (2n)  Eights 23 =8  Fours 22 =4  Twos 21 = 2  Ones 2° = 1
     Binary digit  1  0  1  1
  • The decimal equivalent of 10112 can be worked out as shown below.
    1 x 8 = 8, 0 x 4 = 0, 1 x 2 = 2, 1 x 1 =1, Total = 11

 

Octal Number System

  • The octal number system consists of eight digits running from 0 - 7.
  • The place value of octal numbers go up in factors of eight from right to left as shown.
  • For example to represent an octal number such as 724, we proceed as follows:

     Place values  83 =512  82 =64  81 = 8  8° = 1
     Octal digit  7  2  4  5
  • The decimal equivalent can be worked out as follows:
    7 x 512 = 3 584, 2 x 64 = 128, 4 x 8=32, 5 x 1 = 5 Total = 3749

Hexadecimal Number System

  • This is a base sixteen number system that consist of sixteen digits ranging from 0 - 9 and letters A - F where A is equivalent to 10, B to 11 up to F which is equivalent to 15 in base ten system.
  • The place value of hexadecimal numbers goes up in factors of sixteen as shown.

     Place value  162= 256  161 = 16  16° = 1
     Hexadecimal digit  9  4  6

    Table below gives digits for base 10 and base 16.
     Base 10  0  1  2  3  4  5  6  7  8  9  10  11  12  13  14  15
     Base 16  0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F
  • A hexadecimal number is usually denoted using 16 as a subscript or capital letter H to the right of the number.
  • For example, 94B can be written as 94BI6 or 94BH.
  • The decimal equivalent of 94BI6 can be worked out as shown below.
    9 x 256 =2304, 4 x 16 = 64, 11x 1 =11 total = 2379

Further Conversion of Numbers from one Number System to Another

  • So far, we have looked at the four types of number systems and introduced their basic concepts in a general and limited way.
  • However, in this section, we shall have a detailed look at how to convert numbers from one system to another.
  • The following conversions will be considered.
    • Conversion between binary and decimal numbers.
    • Converting octal numbers to decimal and binary form.
    • Converting hexadecimal numbers to decimal and binary form.

Conversion between binary and decimal numbers

Converting binary numbers to decimal numbers

  1. First write the place values starting from the right hand side.
  2. Write each digit under its place value.
  3. Multiply each digit by its corresponding place value.
  4. Add up the products. The answer will be the decimal number in base 10.

 

Converting decimal numbers to binary

  • To convert a decimal number to binary, there are two possible methods, the long division method and the place value method.
    • In long division method, the decimal number is continuously divided by 2.
    • However, at each level of the division, the remainder which is either a 1 or 0 is written to the right of the quotient.
    • Starting from bottom upwards, read the series of the remainder digits.
    • The series of 1 's and O's obtained represent the binary equivalent of the number.
  • To convert a decimal number to a binary number using place value method proceed as follows:
    • Write down the place values in factors of 2 up to the value immediately larger or equal to the number being considered.
    • For example, to convert 24710 into binary, we write" down the place values up to 28 i.e.256.
    • Similarly to convert 25810' write down the place values up to 29 i.e. 512.
    • If the number being considered is itself a factor of 2 such as 64, 128, 256 etc., then place values should be written up to the number itself.
    • Let us now convert 24710 to binary.
    • Starting from the left as shown in the table below, subtract the place value from the number being converted.
    • If the difference is a positive number or a 0, place a 1 in the binary digit row.
    • If the difference is negative, place a Zero.
    • In the table below, a 0 is placed in the binary digits row of the first column because 247 - 256 gives a negative value.
    • The number 247 is then carried forward to the next lower place value i.e. 128.
       Place value  28  27  26  25  24  23  22  21  2o
       Difference  247 - 256  247 - 128              
       Binary digit  0                

      Since 247 - 128 gives a positive difference of 119, the digit 1 is placed in the second column of the binary digit row and the difference is carried forward to the next lower place value as shown.

       Place value  256
       128
       64
       32
       16
       8
       4
       2
       1
       Difference  247 - 256  247 - 128              
       Binary digit  0  1              

      Table below shows the completed operation.
       256
       128  64
       32
       16
       247 - 256  247 - 128  119 - 64  55 - 32  23 - 16
       0  1  1  1  1


       8  4  2  1
       7-8  7-4  3-2  1-1= 0
       0  1  1  1

Converting a binary fraction to decimal number

  • A decimal number which has both an integral and fractional part is called a real number.
  • The weight of the integral part of a real number increases from right to left in factors of 10 while that of the fractional part decreases from left to right in factors of 10-x.
  • Table below shows how a real number 87.537 can be represented using the place values.

     Place value  101  10°  .  10-1  10-2  10-3
     Decimal digit  8  7  .  5  3  7
     Value  80  7  .  0.5  0.03  0.007
  • For a binary number, the same approach as in the example above can be used, only that the place values (weight) are based on factors of 2. For example, the binary number 11.110112 can be represented as shown in the table below.

     Place value  21  2°  .  2-1  2-2  2-3  2-4  2-5
     Binary digit  1  1  .  1  1  0  1  1
     Value in base ten  2  1  .  0.5  0.25  0  0.0625  0.03125
  • NB: When converting a real number from binary to decimal, work out the integral and fractional parts separately then combine them.

Converting a decimal fraction to binary

  • Remember that to convert a decimal integer to its binary equivalent we continuously divide the number by 2.
  • In real decimal numbers, we do the same for the integral part.
  • However to convert the fractional part to its binary equivalent, we proceed as follows:
    1. Multiply the fractional part by 2 and note down the product.
    2. Take the fractional part of the immediate product and multiply it by 2 again.
    3. Continue this process until the fractional part of the subsequent product is 0 or starts repeating the value of the original fractional part of the number being converted:
    4. The binary equivalent of the fractional part is extracted from the products by reading the respective integral digits from the top downwards.
    5. Combine the two parts together to get the binary equivalent.

Converting octal numbers to decimal and binary numbers

Converting octal numbers to decimal numbers

  • To convert a base 8 number to its decimal equivalent we use the same method as we did with binary numbers.
  • However, it is important to note that the maximum absolute value of an octal digit is 7.
  • For example 982 is not a valid octal number because digits 8 and 9 are not octal digits, but 7368 is valid because all the digits are in the range of 0 - 7. 


    Example

    Convert 275 from octal to decimal.

    Solution
    Write down the place value of each digit.
     82  81  80
     64  8  1
     2  7  5

    Add up the place value of each digit.
    64x2 + 8x7 + 1x5
    = 128 + 56 + 5 = 189
    So 275 in octal is equal to 189.

Converting octal numbers to binary numbers

  • To convert an octal number to binary, each digit is represented by 3 binary digits because the maximum octal digit i.e. 7 can be represented with a maximum of 3 digits.
     Octal digit  Binary equivalents
     0  000
     1  001
     2  010
     3  011
     4  100
     5  101
     6  110
     7  111

    Example
    Convert octal number 540 into binary number.

    According to the above table,
    = (540)8
    = (101 100 000)2
    = (101100000)2

Converting hexadecimal numbers to decimal and binary numbers

Converting hexadecimal numbers to decimal number

  1. First write the place values starting from the right hand side.
  2. If a digit is a letter such as an 'A' write its decimal equivalent.
  3. Multiply each hexadecimal digit with its corresponding place value and then add the products.

    Example

    Convert hexadecimal number ABCDEF into decimal number.
    = (ABCDEF)16
    = (10x165+11x164+12x163+13x162+14x161+15x160)10
    = (10485760+720896+49152+3328+224+15)10
    = (11259375)10 

Converting hexadecimal numbers into binary numbers

  • Since F is equivalent to a binary number 11112, the hexadecimal numbers are represented using 4 digits as shown.

     Decimal equivalent  Hexadecimal digit  Binary equivalent
     00  00  0000
     01  01  0001
     02  02  0010
     03  03  0011
     04  04  0100
     05  05  0101
     06  06  0110
     07  07  0111
     08  08  1000
     09  09  1001
     A  10  1010
     B  11  1011
     C  12  1100
     D  13  1101
     E  14  1110
     F  15  1111
  • The simplest method of converting a hexadecimal number to binary is to express each hexadecimal digit as a four bit binary number and then arranging the groups according to their corresponding positions as shown.

    Example: Convert hexadecimal number 3B2916 to binary

    (0011 1011 0010 1001)2
    00111011001010012

Symbolic Representation Using Coding Schemes

  • In computing, a single character such as a letter, a number or a symbol is represented by a group of bits, the number of bits per character depends on the coding scheme used.
  • The most common coding schemes are the Binary Coded Decimal (BCD), Extended Binary Coded Decimal Interchange Code (EBCDIC) and American Standard Code for Information Interchange (ASCII).

Binary Coded Decimal

  • Binary Coded Decimal is a 4-bit code used to represent numeric data only.
  • For example, a number like 9 can be represented using Binary Coded Decimal as 10012, Binary Coded Decimal system is mostly used in simple electronic devices like calculators and microwaves.
  • This is because it makes it easier to process and display individual numbers on their Liquid Crystal Display (LCD) screens.
  • A standard Binary Coded Decimal, an enhanced format of Binary Coded Decimal, is a 6-bit representation scheme which can represent nonnumeric characters.
  • This allows 64 characters to be represented.
  • For example, letter A can be represented as 1100012 using the standard Binary Coded Decimal.

Extended Binary Coded Decimal Interchange Code (EBCDIC)

  • Extended Binary Coded Decimal Interchange Code (EBCDIC) is an 8bit character coding scheme used primarily on IBM computers.
  • A total of 256 (28) characters can be coded using this scheme.
  • For example, the symbolic representation of letter A using Extended Binary Coded Decimal Interchange Code is 110000012

American Standard Code for Information Interchange (ASCII)

  • American Standard Code for Information Interchange (ASCII) is a 7-bit code, which means that only 128 characters i.e. 27 can be represented.
  • However manufacturers have added an eighth bit to this coding scheme, which can now provide for 256 characters.
  • This 8-bit coding scheme is referred to as an 8-bit American Standard Code for Information Interchange.
  • The symbolic representation of letter A using this scheme is 10000012

Binary Arithmetic Operations

  • In mathematics, the four basic arithmetic operations applied on numbers are addition, subtraction, multiplication and division.
  • In computers the same operations are performed inside the central processing unit by the arithmetic and logic unit (ALU).
  • However the arithmetic and logic unit cannot perform binary subtraction directly.
  • It performs binary subtraction using a process known as complementation.
  • For multiplication and division, the arithmetic and logic unit uses a method called shifting before adding the bits; however, because the treatment of this method is beyond the scope of this book, we shall only explain how the computer performs binary addition and subtraction.

Representation of Signed Binary Numbers

  • In computer technology there are three common ways of representing a signed binary number.
    • Prefixing an extra sign bit to a binary number.
    • Using ones complement.
    • using twos complement.

Prefixing an extra sign bit to a binary number

  • In decimal numbers, a signed number has a prefix "+" for a positive number e.g. +2710 and "-" for a negative number e.g. -2710
  • However in binary, a negative number may be represented by prefixing a digit 1 to the number while a positive number may be represented by prefixing a digit 0.
  • For example, the 7-bit binary equivalent of 127 is 11111112, To indicate that it is positive, we add an extra bit (0) to the left of the number i.e. (0)11111112, To indicate that it is a negative number we add an extra bit (1) i.e. (1)11111112,
  • The problem of using this method is that the zero can be represented in two ways i.e. (0)00000002 and (1 )00000002,

Ones complement

  • The term complement refers to a part which together with another makes up a whole.
  • For example in geometry two complementary angles add up to one right angle (90°).
  • The idea of complement is used to address the problem of signed numbers i.e., positive and negative.
  • In decimal numbers (0 to 9), we talk of nine's complement.
  • For example the nines complement of 9 is 0 that of 5 is 4 while that of 3 is 6.
  • However, in binary numbers, the ones complement is the bitwise NOT applied to the number.
  • Bitwise NOT is a unary operator (operation on only one operand) that performs logical negation on each bit.
  • For example the bitwise NOT of 11002 is 00112 i.e. 0s are negated to 1s while 1's are negated to 0’s.
  • Likewise the bitwise NOT of 00 1 0 11 0 1 is 110100102 which represents -4510'
  • The bitwise NOT of 8-bit zero 000000002 is 111111112, Looking at the two numbers, the most significant digit shows that the number has a sign bit "0" for "+0" and" 1" for "-0".
  • Like in the method of using an extra sign bit, in ones complement, there are two ways of representing a zero.

Twos complement

  • Twos complement, equivalent to tens complement in decimal numbers, is the most popular way of representing negative numbers in computer systems.
  • The advantages of using this method are:
    • There are no two ways of representing a zero, as is the case with the other two methods.
    • Effective addition and subtraction can be done even with numbers that are represented with a sign bit without a need for extra circuitries to examine the sign of an operand.
  • The twos complement of a number is obtained by getting the ones complement then adding a 1.
  • For example, to get the twos complement of a decimal number 4510' first convert it to its binary equivalent then find its ones complement.
  • Add a 1 to the ones complement i.e.
    4510 = 001011012
    Bitwise NOT (00101101) = 11010010
    Two's complement = 110100112

Binary Addition

  • The five possible additions in binary are:
    1. 0+0=0
    2. 0 + 12= 12
    3. 12 + 0 = 12
    4. 12 + 12 =102 (read as 0, carry 1)
    5. 12 + 12 + 12 = 112 (read as 1, carry 1)

Binary Subtraction

Direct subtraction

  • The four possible subtractions in binary are:
    1. 0-0=0
    2. 12-0= 12
    3. 12 - 12 = 0
    4. 102 - 12 = 12 (Borrow 1 from the next most significant digit to make 0 become 102, hence 102 - 12 = 12)

Subtraction using ones complements

  • The main purpose of using the ones complement in computers is to perform binary subtractions.
  • For example to get the difference in 5 - 3, using the ones complement, we proceed as follows:
    1. Rewrite the problem as 5 + (-3) to show that the computer performs binary subtraction by adding the binary equivalent of 5 to the ones complement of 3.
    2. Convert the absolute value of 3 into 8-bit equivalent i.e. 000000112,
    3. Take the ones complement of 000000 112 i.e. 111111002 which is the binary representation of -310'
    4. Add the binary equivalent of 5 to the one's complement of 3 i.e.
        000000101
      +111111000
      (1)00000001
  • Looking at the difference of the two binary numbers, you will observe that:
    • It has a ninth bit. The ninth bit is known as an overflow bit.
    • The result show that the difference between the two numbers is 00000001. This is not true! We know that it should be 00000010.
  • To address this problem in a system that uses ones complement, the overflow digit is added back to the magnitude of the 8-bit difference.
  • Therefore the difference becomes 00000001 + 1 = 00000010, which is the correct answer.

Subtraction using twos complements

  • Like in ones complement, the twos complement of a number is obtained by negating a positive number to its negative counterpart.
  • For example to get the difference in 5 - 3, using the two's complement, we proceed as follows:
    1. Rewrite the problem as 5 + (-3).
    2. Convert the absolute value of 3 into 8-bit binary equivalent i.e. 00000011.
    3. Take the ones complement of 000000 11 i.e. 11111100.
    4. Add a 1 to the ones complement i.e. 11111100 to get 11111101
    5. Add the binary equivalent of 5 to the twos complement of 3 i.e.
        000000101
      +111111001
      (1)00000010
    6. Ignoring the overflow bit, the resulting number is 00000010 which is directly read as a binary equivalent of +2.

Download DATA REPRESENTATION IN A COMPUTER - Computer Studies Form 3 Notes.


Tap Here to Download for 50/-





Join our whatsapp group for latest updates
Read 2284 times Last modified on Monday, 17 January 2022 12:49
Print PDF for future reference