Data Representation in Computers: Binary, Decimal, Octal, and Hexadecimal Systems, Lecture notes of Introduction to Computers

about the basic computer skills and its applications

Typology: Lecture notes

2021/2022
On special offer
30 Points
Discount

Limited-time offer


Uploaded on 03/26/2022

MikeSiera
MikeSiera 🇪🇹

8 documents

1 / 17

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CHAPTER-THREE
3. Data Representation in Computer
Data Representation:smartphones, iPods &computersstoredatain digital (bit 0 or 1)
formats that can be handled by electronic circuitry.
Because a digital computer works with binary number system only.
Data is divided into three types: -
1. Alphabetic (non-numeric): is used to represent the alphabets.
It consists of capital letters A–Z, small letters a – z and blank space etc.
2. Numeric: consists ten digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, two signs (+ –) & decimal point.
3. Alphanumeric: is used to represent alphabetic or numeric data, special characters &
symbols.
3.1. Number System
Every computer store numbers, letters & other special characters in a coded form. Before
going into the details of these codes, it is essential to have a basic understanding of number
system. Number systems are basically of two types: non positional and positional.
A. Non-Positional Number Systems
In this system, we have symbols such as I for 1, II for 2, III for 3, IIII for 4 etc. Each symbol
represents the same value regardless of its position in the number and the symbols are simply
added to find out the value of a particular number. Since it is very difficult to perform
arithmetic with such number system because there is no symbol for zero.
B. Positional Number Systems
In the early days Non-Positional number system was very difficult to use, as it had no symbol
for 0. In positional number system there are only a few symbols called digits & these symbols
represent different values depending on the position they occupy in the number. The value of
each digit in such a number is determined by three considerations.
The digit itself.
The position of the digit in the number
The base or radix (where base is determined as total number of digits available in the
number system)
We will introduce here 4 positional number systems
1. Binary: representing data either by "0" or "1".
Page - 1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
Discount

On special offer

Partial preview of the text

Download Data Representation in Computers: Binary, Decimal, Octal, and Hexadecimal Systems and more Lecture notes Introduction to Computers in PDF only on Docsity!

CHAPTER-THREE

3. Data Representation in Computer

Data Representation: smartphones, iPods & computers store data in digital (bit 0 or 1) formats that can be handled by electronic circuitry.  Because a digital computer works with binary number system only.  Data is divided into three types: -

1. Alphabetic (non-numeric) : is used to represent the alphabets.  It consists of capital letters A–Z, small letters a – z and blank space etc. 2. Numeric: consists ten digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, two signs (+ –) & decimal point. 3. Alphanumeric: is used to represent alphabetic or numeric data, special characters & symbols.

3 .1. Number System

Every computer store numbers, letters & other special characters in a coded form. Before going into the details of these codes, it is essential to have a basic understanding of number system. Number systems are basically of two types: non positional and positional. A. Non-Positional Number Systems In this system, we have symbols such as I for 1, II for 2, III for 3, IIII for 4 etc. Each symbol represents the same value regardless of its position in the number and the symbols are simply added to find out the value of a particular number. Since it is very difficult to perform arithmetic with such number system because there is no symbol for zero. B. Positional Number Systems In the early days Non-Positional number system was very difficult to use, as it had no symbol for 0. In positional number system there are only a few symbols called digits & these symbols represent different values depending on the position they occupy in the number. The value of each digit in such a number is determined by three considerations.  The digit itself.  The position of the digit in the number  The base or radix (where base is determined as total number of digits available in the number system)  We will introduce here 4 positional number systems

1. Binary: representing data either by "0" or "1".

 The base or radix of the binary number system is 2.

2. Octal: there is 8 possibilities: 0, 1, 2, 3, 4, 5, 6 & 7.  The base or radix of the octal number system is 8. 3. Decimal: includes whole numbers. (0-9). we use in our day-to-day life 4. Hexadecimal: have 16 symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E & F.  The base or radix of the hexadecimal number system is 16.  Comparative Representation of Number Systems

Decimal Binary Octal Hexadecimal 0 0 0 0 1 1 1 1 2 10 2 2 3 11 3 3 4 100 4 4 5 101 5 5 6 110 6 6 7 111 7 7 8 1000 10 8 9 1001 11 9 10 1010 12 A 11 1011 13 B 12 1100 14 C 13 1101 15 D 14 1110 16 E 15 1111 17 F : : : :

2.1.1. Conversion between Number Systems

Internally computers use binary numbers for data representation whereas externally it uses decimal numbers. However, any number in one number system can be represented in any other number system.

1. Conversion of Decimal to Binary (Remainder Method)

 This method involves the following steps:

  1. Divide the number by 2 and store the remainder.
  2. Divide the quotient by 2 and store the remainder.
  3. Repeat these steps until quotient becomes 0.

Step 1: Multiply each digit of binary from left to right by base–1, base–2, base–3^ and base– Step 2: Simplify arithmetic expression & add them together to find required fraction. Step 3: Combining both converted parts, we can find decimal equivalent of the binary number. Binary to Decimal (conversion of a binary number to decimal number base / radix will be 2) Example 2 : Convert binary (1100) 2 to decimal form. (?) 10 Solution

Digit Positional value (Step

Step 2

0(right most digit)

20 0×2^0

0 21 0×2^1

1 22 1×2^2

1 23 1×2^3

Total (Step 3) 4+8= Therefore 1100 2 =12 10 Example 3: Convert binary (11101101.10101) 2 to decimal form. Solution : Integer part: 11101101 & Fractional part: 10101 Conversion of integer part: 1×2^7 + 1×2^6 + 1×2^5 + 0×2^4 + 1×2^3 + 1×2^2 + 0×2^1 + 1×2^0 1×128 + 1×64 + 1×32 + 0×16 + 1×8 + 1×4 + 0×2 + 1× 128 + 64 + 32 + 0 + 8 + 4 + 0 + 1 (237) 10 Conversion of fractional part:  Starting from left to right each bit is multiplied by 2–1, 2–2, 2–3, 2–4...... we find 1 0 1 0 1 1×2–1^ + 0×2–2^ + 1×2–3^ + 0×2–4^ + 1×2– .50 + 0 + .125 + 0 + .03125 = (.65625) 10 By combining both the resultant values we get the final decimal equivalent value (237.65625) 10 Example 4: (10111.1)2 = (?)10 solution: 1 × 2^0 + 1 × 2^1 + 1 × 2^2 + 0 × 2^3 + 1 × 2^4 + 1x 2- = 1 + 2 + 4 + 0 + 16 +0.5(= ½ =0.5) = (23.5) 10

3. Conversion of Octal to Decimal

(For conversion of an octal number to a decimal number the base / radix will be 8.)

 Multiplying each digit from right side with increasing power of 8 and adding the result.  This means, the first digit from right will be multiplied by 8^0 , the second digit with 8^1 …. Example 1: (1505) 8 =? = 5 × 8^0 + 0 × 8^1 + 5 × 8^2 + 1 × 8^3 = 5 + 0 + 320 + 512 = (837) 10

Example 2: Convert octal number (172) 8 to decimal (?) 10 Solution Conversion of integer part: Starting from right multiply each digit by its positional value, we find 1 7 2 1×8^2 + 7×8^1 + 2×8^0 1×64 + 7×8 + 2× 64 + 56 + 2 (122) 10 So, decimal equivalent value of (172) 8 is (122) 10 Example 3 : Convert (342.671) 8 to decimal (?) 10 form. Solution Integer part: 342 & Fractional part: 671 Conversion of integer part 3 4 2 = 3×8^2 + 4×8^1 + 2×8^0 = 3×64 + 4×8 + 2×1 = 192 + 32 + 2 = (226) 10 Conversion of fractional part Starting from left to right each digit is multiplied by 8–1, 8–2, 8–3, 8–4...... we find – 6 7 1 6×

+ 7×8–2^ + 1×8–

By combining both the converted values we get the final decimal equivalent (226.86125) 10

4. Converting Decimal to Octal

 To convert a decimal number to its equivalent octal number, follow these steps:

  1. Divide the number by 8 and store the remainder.
  2. Divide the quotient by 8 and store the remainder.
  3. Repeat these steps until quotient becomes 0.
  4. Write the remainders from bottom to top order.

Converting from Decimal to a New Base

A. Integer part conversion Step 1: Divide the decimal number to be converted by the value of new base. Step 2: Record the remainder from step 1 as the rightmost digit (Least Significant Digit) of the new base number. Step 3: Divide the quotient of the previous division by the new base. Step 4: Record the remainder from step 3 as the next digit (to the left) of new base number. Step 5: Repeat steps 3 and 4 recording remainders from right to left, until the quotient becomes zero in step 3. Note that the last remainder thus obtained will be the most significant digit (MSD) of the new base number.

B. Fractional part conversion

  1. In this method we multiply given fractional part by ‘base’ and write down the Fractional parts and integer parts of the products in the separate columns.
  2. The successive fractional parts of the products are multiplied by base till the fractional part of the product becomes 0 or up to the desired accuracy.
  3. The integer part of the product is written in downward direction ( ) to find the binary equivalent of the decimal fraction. Example 1:

Decimal to Binary Decimal to Octal Decimal to Hexadecimal 2510 =? 2 95210 =? 8 42810 =? 16 Q R Q R Q R 25÷2 12 1 12÷2 6 0 6 ÷2 3 1 3÷2 1 0 1 ÷ 2 0 1 = 11001 2

952÷8 119 0

119÷8 14 7

14÷8 7

6 7÷8 1

1÷8 0

428÷16 26

26÷16 1

1÷16 0 1

=1 A C 16

`

Example 2: Find the Binary equivalent of (75.68) 10 = (?) 2 Solution:

Example 3 : Find the Octal equivalent of (634.640625) 10 = (?) 8 Solution: Integer part conversion Divisor Dividend ÷ divisor Quotient Remainder 8 8 8 8

634 ÷ 8

79 ÷ 8

9 ÷ 8

1 ÷ 8

2 LSD

1 MSD

Fractional part conversion Process Product Decimal Part Integer part 0.640625 × 8 5.125 .125 5 MSD 0.125 × 8 1.00 .00 1 = (510) 8 0.00 × 8 0.00 .00 0 LSD Now the combined string of converted integer and fractional part will be - (634.640625)10 = (1172.510 ) 8 Example 4: Find the Hexa-decimal equivalent of (3634.6505) 10 = (?) 16 Solution:

Word is a fixed-sized group of bits that are handled together by machine. The number of bits in a word (the word size or word length ) is an important characteristic of computer architecture. A Word consists of 32 bits , which is equal to 4 bytes (this depends on the computer i.e., a word may contain 8, 16, or 32 bits). Commonly used notation in modern computers is 32 bits. Double word is 2 times a word.

Memory capacity

 Frequently capacity of memory is represented in terms of K (Kilo), which is equivalent to 1024 words of 8 bits each (2^10 bytes).

Why Binary representation is

used in computers?

Computer’s internal storage technique, different from people represent information in lives. Information inside a digital computer is stored as a collection of binary data (0’s and 1’s) It was easier to make hardware which can distinguish b\n two values than multiple values. Other bases need more circuitry as compared to binary and this reduced reliability. Binary system simplifies the design of circuits, reduces the cost & improves the reliability. Every operation that can be done in decimal system can also be done in binary.

3.2. Computer Codes

 Computer handles different types of data namely numeric, alphanumeric, alphabetic etc.  Computer system use a binary system for data representation; two digits 0 and 1, refer to absence & presence of electric current or pulse of light.  All data and programs that go into the computer are represented in terms of these numbers.  Computer system encodes the data by means of binary or digital coding schemes to represent letters, numbers & special characters.  One of the early coding schemes is BCD.  Some of the commonly used schemes are EBCDIC, ASCII and Unicode.

I. BCD (Binary Coded Decimal)

 BCD is one of the early memory codes.

These are all the approximate values B stands for Byte

1 KILO = 1024 bytes (approx. 103 bytes) 1 MEGA = 10^3 K B 1 GIGA = 10^3 M B 1 TERA = 10^3 G B 1 PETA = 10^3 TERA B

 In BCD each digit of a decimal number is converted into its binary equivalent rather than converting the entire decimal value into binary form.  Each decimal digit uses 4 bits for this conversion.

Char acter

BCD Code (^) Equivalent

Digit Zone Octa l Digit 0 00 0000 00 00 1 00 0001 01 1 2 00 0010 02 2 3 00 0011 03 3 4 00 0100 04 4 5 00 0101 05 5 6 00 0110 06 6 7 00 0111 07 7 8 00 1000 10 8 9 00 1001 11 9

Char acter

BCD Code (^) Equivalent

Digit Zone Octa l Digit A 11 0001 61 49 B 11 0010 62 50 C 11 0011 63 51 D 11 0100 64 52 E 11 0101 65 53 F 11 0110 66 54 G 11 0111 67 55 H 11 1000 70 56 I 11 1001 71 57

 1010 = 0001 0000 in BCD  1510 = 0001 0101 in BCD  Since 4 bits is insufficient to represent characters, 6 bits representation was introduced in BCD coding. 6 bits is enough to represent 10 decimal digits , 26 alphabetic letters and 28 other special characters. Also using 6 bits we can represent 2^6 (=64) different characters.  6-bit BCD code can be easily divided into 3-bit groups & each group can be represented by 1 octal digit.  Thus, octal number system is used as a shortcut notation for memory dump by computers that use BCD code for internal representation characters.  BCD is still heavily used in IBM processors and databases, such as IBM DB2. Example 1: Write a BCD code for the word CASE Solution: C= 11 0011 A = 11 0001 S = 01 0010 E = 1 1 0101 The BCD code for CASE is = 110011 110001 010010 110101

II. EBCDIC (Extended Binary Coded Decimal Interchange Code)

 Using 6 bits BCD can represent only 64 characters. To represent lowercase alphabets (26), uppercase alphabets (26), decimal numbers (10) and special characters (28+) BCD coding is not sufficient and was extended from 6 bit to 8 bits. And the new coding scheme is EBCDIC. EBCDIC using 8 bits can represent 2^8 (=256) different characters.  EBCDIC 8-bit coding can be divided into 2 groups of 4 bits. Each group can be represented using 1 hexadecimal digit.

 EBCDIC Coding Scheme for All Numeric and Alphabetic Characters

Example 1 : Find the EBCDIC code for PEN Solution By using EBCDIC table P E N 1101 0111 1100 0101 1101 0101 The EBCDIC code for PEN is 1101 0111 1100 0101 1101 0101

III. ASCII

 Pronounced “ask-ee”, ASCII ( A merican S tandard C ode for I nformation I nterchange) is the binary code most widely used with microcomputers.  ASCII 7-bit code can represent up to 128 characters. A letter, digit or special symbol is called a character.  It includes upper-case and lower-case alphabets, numbers, punctuation marks, special characters and control characters.  ASCII 8-bit code can represent up to 256 characters.  A – Z = 65 - 90, a – z = 97 – 122, and 0 – 9 = 48 – 57

Rule to follow when binary numbers are:

1. Addition 0 + 0 = 0 0 + 1 = 1 1 + 0 = 1 1 + 1 = 0 (with a carry of 1) 2. Subtraction 0 - 0 = 0 1 - 0 = 1 1 - 1 = 0 0 - 1 = 1 (with a borrow of 1) 3. Multiplication 0 x 0 = 0 0 x 1 = 0 1 x 0 = 0 1 x 1 = 1 4. Division 0 / 1 = 0 1 / 1 = 1 Example :

Introduction to Computer

(Individual Assignment I (20%)) To 2nd^ year: Follow all necessary steps

  1. Write the ASCII-8 code for the word “ YEaR ”? (5 points)
  2. Write BCD code for your First 3 letters of your first Name? hint (A - Z) (5 points)
  3. Convert the given number to its equivalent. (2.5 point for each) A. (ABDE) 16 = (?) 2 B. (52.4321) 8 =(?) 16 C. (234) 10 = (?) 2 D. (01010101) 2 =(?) 10

Assignment Submission date: 11/08/2013 E.C

N.B : Neatness and readability will have Value!!!