Data Representation in Computers
Binary Representation of Data:
In order to work with data, the data must be represented inside the computer. Digital computers represent data by means of an easily identified symbol called a digit.
Numbering Systems:
Each number system has a base also called a Radix. A decimal number system is a system of base 10; binary is a system of base 2; octal is a system of base 8; and hexadecimal is a system of base 16.
Number System Base Symbols used
Binary 2 0,1
Octal 8 0,1,2,3,4,5,6,7
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 where A = 10; B = 11; C = 12; D = 13; E = 14; F = 15
Converting a number from one Base to another
Decimal to Binary
Method to convert a Decimal number into its Binary equivalent
1. Divide the decimal number by 2.
2. Take the remainder and record it on the side.
3. Divide the quotient by 2.
4. REPEAT UNTIL the decimal number cannot be divided further.
5. Record the remainders in reverse order and you get the resultant binary number.
Example
Convert the Decimal number 125 into its Binary equivalent.
125 / 2 = 62 1
62 / 2 = 31 0
31 / 2 = 15 1
15 / 2 = 7 1
7 / 2 = 3 1
3 / 2 = 1 1
1 / 2 = 0 1
Answer: (1111101)2
2. Converting Decimal fraction to Binary
Example:
Convert (0.75)10 to binary
- Multiply the given fraction by 2.
- Keep the integer in the product as it is and multiply the new fraction in the product by 2.
- Continue the process till the required number of decimal places or till you get zero in the fraction part.
- Record the integers in the products from top to bottom.
Given fraction 0.75
Multiply 0.75 by 2 =1.50
Multiply 0.50 by 2 = 1.00
Reading the integers from top to bottom 0.75 in decimal number system is 0.11 in binary number system.
Binary to Decimal
Method to convert Binary to Decimal:
1. Start at the rightmost bit.
2. Take that bit and multiply by 2n where n is the current position beginning at 0 and increasing by 1 each time. This represents a power of two.
3. Sum each terms of product until all bits have been used.
Example
Convert the Binary number 101011 to its Decimal equivalent.
1*25 + 0*24 + 1*23 + 0*22 + 1*21 + 1*20
32 + 0 + 8 + 0 +2 + 1 = (43)10
Example
Convert the Binary number 1001 to its Decimal equivalent.
1*23 + 0*22
+ 0*21 + 1*20
8 + 0 + 0 + 1 = (9)10
Binary fraction to decimal
Example
Convert (11011.101)2 to decimal
1 1 0 1 1 .1 0 1
= (1 x 24) + (1 x 23) + (0 x 22) + (1 x 21) + (1 x 20) + (1 x 2-1) + (0 x 2-2) + (1 x 2-3)
= 16+8+0+2+1+0.5+0+0.125
= (27.625)10
Decimal to Octal
The method to convert a decimal number into its octal equivalent:
1. Divide the decimal number by 8.
2. Take the remainder and record it on the side.
3. Divide the quotient by 8.
4. REPEAT UNTIL the decimal number cannot be divided further.
5. Record the remainders in reverse order and you get the resultant binary
Example
Convert the Decimal number 125 into its Octal equivalent.
125 / 8 = 15 5
15/ 8 = 1 7
1/8 =0 1
Answer: (175)8
Converting Decimal fraction to Octal
Example
Convert (0.75)10 to Octal
- Multiply the given fraction by 8. Keep the integer in the product as it is and multiply the new fraction in the product by 8.
- Continue the process and read the integers in the products from top to bottom.
Given fraction 0.75
Multiply 0.75 by 8 6.00
Reading the integers from top to bottom 0.75 in decimal number system is 0.6 in octal number system.
Octal to Decimal
Method to convert Octal to Decimal:
1. Start at the rightmost bit.
2 . Take that bit and multiply by 8n where n is the current position beginning at 0 and increasing by 1 each time. This represents the power of 8.
3. Sum each of the product terms until all bits have been used.
Example
Convert the Octal number 321 to its Decimal equivalent.
3*82 + 2*81 + 1*80
192+16+ 1 = (209)10
Octal fraction to decimal
Example
Convert (23.25)8 to decimal
81 80 . 8-1 8-2
= (2 x 81) + (3 x 80) + (2 x 8-1) + (5 x 8-2)
= 16 + 3 + 0.25 + 0.07812
= (19.32812)10
Decimal to Hexadecimal
Method to convert a Decimal number into its Hexadecimal equivalent:
1. Divide the decimal number by 16.
2. Take the remainder and record it on the side.
3. REPEAT UNTIL the decimal number cannot be divided further.
4.Record the remainders in reverse order and you get the equivalent hexadecimal number.
Example
Convert the Decimal number 300 into its hexadecimal equivalent.
300 / 16 = 18 12-(C)
18 / 16 = 1 2
1 / 16 = 0 1
Answer: (12C)16
Converting Decimal fraction to Hexadecimal
Example
Convert (0.75)10 to hexadecimal
- Multiply the given fraction by 16. Keep the integer in the product as it is and multiply the new fraction in the product by 16.
- Continue the process and read the integers in the products from top to bottom.
Given fraction 0.75
Multiply 0.75 by 16 12.00 - C
Reading the integers from top to bottom 0.75 in decimal number system is 0C in Hexadecimal number system.
Hexadecimal to Decimal
Method to convert Hexadecimal to Decimal:
1. Start at the rightmost bit.
2. Take that bit and multiply by 16n where n is the current position beginning at 0 and increasing by 1 each time. This represents a power of 16.
3. Sum each terms of product until all bits have been used.
Example
Convert the Hexadecimal number AB to its Decimal equivalent.
=A * 161 + B * 160
=10 * 161
+ 11 * 160
=160+11 = (171)10
Hexadecimal fraction to decimal
Example
Convert (1E.8C)16 to decimal
161 160 . 16-1 16-2
1 E 8
C
= (1 x
161)+ (14 x 160)+ (8 x 16-1)+ (12 x 16-2)
= 16 + 14 + 0.5 + 0.04688
= (30.54688)10
Binary to Hexadecimal
The hexadecimal number system uses the digits 0 to 9 and A, B, C, D, E, F.
Method to convert a Binary number to its Hexadecimal equivalent is:
We take a binary number in groups of 4 and use the appropriate hexadecimal digit in it’s place. We begin at the rightmost 4 bits. If we are not able to form a group of four, insert 0s to the left until we get all groups of 4 bits each. Write the hexadecimal equivalent of each group. Repeat the steps until all groups have been converted.
Example
Convert the binary number 1000101 to its Hexadecimal equivalent.
0100 0101 (Note that we needed to insert a 0 to the left of 100.)
4 5
Answer: (45)16
In case of a fractional binary number form groups of four bits on each side of decimal point. Then replace each group by its corresponding hexadecimal number.
Example
Convert (11100.1010)2 to hexadecimal equivalent.
0001 1100 . 1010
1 C . A
Answer : (1C.A)16
Hexadecimal to Binary
Method to convert a Hexadecimal number to its Binary equivalent is:
Convert each digit of Hexadecimal Number to it’s binary equivalent and write them in 4 bits. Then, combine each 4 bit binary number and that is the resulting answer.
Example
Convert the Hexadecimal number (10AF)16 to its Binary equivalent.
1 0 A F
0001 | 0000 | 1010 | 1111
Answer: (0001000010101111)2
Example
Convert the Hexadecimal number (A2F)16 to its Binary equivalent.
A 2 F
1010 | 0010 | 1111
Answer: (1010 0010 1111)2
Binary to Octal and Octal to Binary
To convert Binary to Octal, as the octal system is a power of two (23), we can take the bits into groups of 3 and represent each group as an octal digit. The steps are the same for the binary to hexadecimal conversions except we are dealing with the octal base now.
To convert from octal to binary, we simply represent each octal digit in it’s three bit binary form.
Example
Convert the Octal number (742)8 to its Binary equivalent.
7 | 4 | 2
111 | 100 | 010
Answer: (111100010)2
Hexadecimal to Octal and Octal to Hexadecimal
To convert Hexadecimal to Octal, Convert each digit of Hexadecimal Number to it’s binary equivalent and write them in 4 bits. Then, combine each 3 bit binary number and that is converted into octal.
Example
Convert the Hexadecimal number (A42)16 to its Octal equivalent.
A | 4 | 2
1010 | 0100 | 0010
101 | 001 | 000 | 010
Answer: (5102)8
To convert Octal to hexadecimal, convert each digit of Octal Number to it’s binary equivalent and write them in 3 bits. Then, combine each 4 bit binary number and that is converted into hexadecimal.
Example
Convert the Octal number (562)8 to its hexadecimal equivalent.
5 | 6 | 2
101 | 110 | 010
0001 | 0111 | 0010
Answer: (172)16
The following table summarizes the number representation in decimal, binary, octal and hexadecimal number system:
Decimal Binary Octal Hexadecimal
0 0000 0 0
1 0001 1 1
2 0010 2 2
3 0011 3 3
4 0100 4 4
5 0101 5 5
6 0110 6 6
7 0111 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
- 26 upper case letters (A-Z)
- 26 lower case letters (a-z)
- 10 digits (0-9)
- 7 punctuation marks
- 20 to 40 special characters
- ASCII
- ISCII
- UNICODE
- The ability of a computer system to understand signals or letters depends on its character set.
- Character set has its standards known as character set code like - ASCII, ISCII, UNICODE etc.
- ASCII ( American Standard Code for Information Interchange) most of the micro computers, mini computers and some mainframe computers uses this code.
- ASCII code has two versions - ASCII – 7 and ASCII – 8.
- ASCII – 7 code use 7 bits for one signal or character. By this, 27 = 128 , different characters can be used.
- ASCII – 8 code use 8 bits for one signal or character. By this, 28 = 256 , different characters can be used.
- This is Universal Character Set which represents a signal or a character in a group of 32 bit.
- It has the capability to include signals and characters from all scripts of all languages of world.
- Before the development of Unicode, various encoding system were in use.
- Problems related to language on internet has been resolved by the use of Unicode.
- The Unicode Standard is the universal character encoding standard for written characters and text. Each character or symbol is assigned a unique numeric value, largely within the framework of ASCII. Earlier, each script had its own encoding system, which could conflict with each other.
- The purpose of Unicode is to −
- Unicode 13.0 adds 5930 characters, for a total of 143,859 characters. These additions include 4 new scripts, for a total of 154 scripts, as well as 55 new emoji characters.
- It was originally designed by Ken Thompson and Rob Pike in 1992.
- UTF-8 encodes each Unicode character as a variable number of 1 to 4 octets, where the number of octets depend on the integer value assigned to the Unicode character.
- At the time of its introduction, ASCII was the most popular character encoding. In ASCII all letters, digits and symbols were assigned a number. And this number, being fixed to 8 bits, it could only represent a maximum of 255 characters, and it wasn’t enough.
- UTF-8 was designed to be backward compatible with ASCII. Because ASCII was much older (1963) and widespread, and moving to UTF-8 was challenging.
- The first 128 characters of UTF-8 map exactly to ASCII.
- Why 128? Because ASCII uses 7-bit encoding, which allows up to 128 combinations. Why 7 bits? Later when ASCII was conceived, 7 bit systems were popular as well. Being 100% compatible with ASCII makes UTF-8 also very efficient.
- UTF-32 always uses 4 bytes, without optimizing for space usage, and as such it wastes a lot of bandwidth.
- This constrain makes it faster to operate on because you have less to check, as you can assume 4 bytes for all characters.
- It’s not as common as UTF-8 and UTF-16, but it has its applications. The key use of UTF-32 is in internal APIs where the data is single code points / glyphs, rather than strings of characters. Used on Unix systems sometimes for storage of information.
- It is a fixed length encoding scheme that uses exactly 4 bytes to represent all Unicode code points.
BOOLEAN ALGEBRA
for boolean algebra please download pdf notes from the following link:
SAMPLE PAPER FOR PT-1
No comments:
Post a Comment