• No results found

Number System and Computer Codes

N/A
N/A
Protected

Academic year: 2020

Share "Number System and Computer Codes"

Copied!
27
0
0

Loading.... (view fulltext now)

Full text

(1)

1

B N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer Science Computer Codes

Representation of Binary data Binary Arithmetic

Fractional number convertions

Convertion of Hexa Decimal Number System to Other base number system Convertion of Octal Number System to Other base number system Convertion of Binary Number System to Other base number system Convertion of Decimal Number System to Other base number system

Types of Number Systems Introduction to Number System

Number System and Computer Codes

Number System and Computer Codes

Number System and Computer Codes

Number System and Computer Codes

(2)

2

B N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer Science

Chapter-4

Number Systems and Computer Codes

Introduction

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.

Bit is the form of ‘binary digit’. It is smallest possible unit of data. A bit can be either 0 or 1.

Nibble is a group of four bits.

Byte is a group of eight bits.

Word is a group of two bytes.

Term Size(bits) Example

Bit 1 0

Nibble 4 1010

Byte 8 0101 1100

word 16 0101 1100 0101 1100

*********************************************************************************** Numbering System and its types

A number system in computer is "A set of values used to represent different quantities is known

asNumber System". For example, a number system can be used to represent the number of students in a

class or number of viewers watching a certain TV program etc. Some important number systems are as follows.

Decimal number system

Binary number system

Octal number system

Hexadecimal number system

Types of number system

Binary Number System

• Represents two types of digits 0's and 1's, so the base of number system is 2.

• Uses two types of electronic pulses, where absence of pulse shows 0 and presence of pulse

shows 1.

• Each binary digit is called as bit.

• Left-most bit of a number is known as Most Significant Bit (MSB) and right-most bit is known

as Least Significant Bit (LSB). Its same for all number system.

(3)

3

B N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer Science

• Value of digit is determined by the position of digit in the number, where lowest value is for the

right-most position and each successive position to the left has a higher place value. Its same for all number system.

• Examples: a) (010101)2 b) (1010.101)2

Octal Number System

• Represents 8 types of digits from 0 to 7, so the base of number system is 8.

• It takes exactly three binary digits to represent an octal digit.

• Binary 000 is same as octal digit 0, binary 001 is same as octal 1, and so on.

• Insufficient to convert values into bytes(8 bit), so not widely used in computers.

• Examples: a) (03105)8 b) (4237.23)8

Decimal Number System

• Represents 10 types of digits from 0 to 9, so the base of number system is 10.

• This is the most familiar number system with everyone.

• Examples a) (582938)10 b) (3797.902)10

Hexadecimal Number System

• Represents 16 types of digits from 0 to 9 and alphabets from A to F, so the base of number

system is 16.

• Digits from 10 to 15 are represented as 10-A, 11-B, 12-C, 13-D, 14-E, 15-F.

• As numeric digits and alphabets are used to represent digits, this number system is also called as

alphanumeric number system.

• More complex number system and widely used in computer system.

• Examples: a) (AF38)16 b) (CE7.5B)16

Number System Base Symbols used

Binary 2 0,1

Decimal 10 0,1,2,3,4,5,6,7,8,9

Octal 8 0,1,2,3,4,5,6,7

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

(4)

4

B N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer Science

NUMBER CONVERSIONS

Model-1: Decimal number system to other base number system

Decimal to Binary

Decimal to Octal

Decimal to Hexa Decimal

1. Decimal to binary conversion Steps:

• Divide the number by two and keep track of the remainder.

• Stop when quotient reaches to zero.

• Arrange these remainders horizontally from bottom to top.

• For fraction part it is multiplied by 2 and keeping track of integers generated.

• Arrange these integers as they are generated.

Example:

Convert (38.625)10 into binary

(38.625)10 = (100110.101)2

2. Decimal to octal conversion Steps:

• Same as decimal to binary conversion but it is divided by 8 to integer part and multiplied by 8

to fractional part. Example:

Convert (180.6875)10 to octal

(5)

5

B N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer Science

3. Decimal to hexadecimal conversion

Steps:

• Same as above but divide by 16 for integer part and multiply by 16 to fractional part.

Example:

Convert (90.675)10 to hexadecimal

(90.675)10 = (5F.A)16

***********************************************************************************

Model-2: Conversion of Binary Number System to Other base number system

• Conversion of Binary to Decimal

• Conversion of Binary to Octal

• Conversion of Binary to Hexadecimal

Binary Number:

A number is said to be a binary number, when its base is 2 and it contains only two digits, 0 and 1. In binary number, each and every number is represented by these two digits.

Example 1: 0101 is equal to 5. Example 2: 1111 is equal to 15.

Decimal Number:

A number is said be a decimal number, when its base is 10 and it can be written with the help of ten digits that are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. All the numbers can be written with the help of these ten digits.

Example 1: 41 Example 2: 551 Example 3: 674

4. Converting Binary to Decimal

Question 1: Convert 1101 to decimal number? Solution:

Binary number is 1101.

So, 1101 = (1 X 23) + (1 X 22) + (0 X 21) + (1 X 20) = (1 X 8) + (1 X 4) + (0 X 2) + (1 X 1) = 8 + 4 + 0 + 1

Correct answer is 13

Question 2: Convert 1001 to decimal number? Solution:

Binary number is 1001.

(6)

6

B N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer Science

= (1 X 8) + (0 X 4) + (0 X 2) + (1 X 1) = + 0 + 0 + 1

Correct answer is 9

5. Converting Binary to Octal

In this article we are going to learn about binary to octal conversion. Here we convert a number to the base 2 to the number to the base 8.

We cannot directly convert binary to octal, so we first convert binary to decimal the decimal to octal number system. Binary numbers are commonly used in computers and octal numbers are used in electronics.

Octal number:

The number to the base 8 is called as octal numbers. It uses numbers from 0 to 7. The numbers

8 and 9 are not there in octal number system. It is denoted by a8 where a is a number with digits 0 to 7.

Examples : (2145)8 , 71658 , 468

Question 1: Convert (1010101)2 to octal

Solution:

Given binary number is (1010101)2

First we convert given binary to decimal

(1010101)2 = (1 * 26) + (0 * 25 ) + (1 * 24) + (0 * 23) + (1 * 22) + (0 * 21) + (1 * 20)

= 64 + 0 + 16 + 0 + 4 + 0 + 1 = 64 + 21

= 85 (Decimal form)

Now we will convert this decimal to octal form 8 | 85

--- 8 | 10 -- 5 --- 8 | 1 -- 2 --- 8 | 0 --1

Therefore, (1010101)2 = (85)10= (125)8

Question 2: Convert (01101)2 to octal

Solution:

Given binary number is (01101)2

First we convert given binary to decimal

(01101)2 = (0 * 24) + (1 * 23) + (1 * 22) + (0 * 21) + (1 *20)

= 0 + 8 + 4 + 0 +1 = 13(Decimal form)

Now we will convert this decimal to octal form 8 | 13

--- 8 | 1 -- 5 --- 8 | 0 -- 1

(7)

7

B N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer Science

6. Convert Binary number to Hexadecimal number

Both binary numbers and hexadecimal numbers are generally used in digital electronic system. In binary, we represent the number in two digits, 0 and 1. In binary number, the base is 2. In hexadecimal number, the base is 16.

The sixteen digits used in this number system are numbers from 0-9 and alphabets from A - F. We can't directly convert binary to hexadecimal. First, we have to convert binary to decimal number system. Then, convert that decimal number to hexadecimal number system.

Binary Decimal Hexadecimal

0000 0 0

0001 1 1

0010 2 2

0011 3 3

0100 4 4

0101 5 5

0110 6 6

0111 7 7

1000 8 8

1001 9 9

1010 10 A

1011 11 B

1100 12 C

1101 13 D

1110 14 E

1111 15 F

Question 1: Convert (01011011)2 in hexadecimal number.

Solution:

The given binary number is 01011011 Now, we convert it first to decimal number

So, 01011011 =(0 X 27) + (1 X 26) + (0 X 25) + (1 X 24) + (1 X 23) + (0 X 22) + (1 X 21) + (1 X 20)

= (0 X 128) + (1 X 64) + (0 X 32) + (1 X 16) + (1 X 8) + (0 X 4) + (1 X 2) + (1 X 1) = 0 + 64 + 0 + 16 + 8 + 0 + 2 + 1

= 91 (decimal form of binary number).

Now, we have to change it into hexadecimal number. So, 91 is greater than 16. So, we have to divide by 16.

After dividing by 16, quotient is 5 and remainder is 11. Remainder is less than 16.

Hexadecimal number of remainder is B.

(8)

8

B N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer Science

That is, 91 = 16 * 5 +11 5 = 16 * 0 + 5

So, 5B is the hexadecimal number equivalent to decimal number 91.

Therefore, (01011011)2 = (91)10=(5B)16

Question 2: Convert (00010111)2 in hexadecimal number.

Solution:

The given binary number is 00010111 Now, we convert it first to decimal number

So, 00010111 =(0 X 27) + (0 X 26) + (0 X 25) + (1 X 24) + (0 X 23) + (1 X 22) + (1 X 21) + (1 X 20) = (0 X 128) + (0 X 64) + (0 X 32) + (1 X 16) + (0 X 8) + (1 X 4) + (1 X 2) + (1 X 1)

= 0 + 0 + 0 + 16 + 0 + 4 + 2 + 1 = 23 ( It is in decimal from)

Now, we have to change it to hexadecimal number. So, 23 is greater than 16, so we have to divide it by 16. After dividing by 16 , quotient is 1 and remainder is 7. Remainder is less than 16.

The hexadecimal number of remainder is 7.

Quotient is 1 and hexadecimal number of remainder is 7. That is, 23 = 16 * 1 + 7

1 = 16 * 0 + 1

So, 17 is the hexadecimal number is equivalent to decimal number 23.

Therefore, (00010111)2=(23)10=(17)16

*********************************************************************************** Model-3: Conversion of Octal Number System to Other base number system

Convert Octal to Binary

Convert Octal to Decimal

Convert Octal to Hexadecimal.

7. Convert Octal to Binary

Here we are going to learn how to convert an octal to binary. That is here we are converting a number to the base 8 to the equivalent number to the base 2.

In converting an octal number to an binary number we follow two steps. First we convert the given octal number to the equivalent decimal number. Then the second step it to convert this decimal number to its equivalent binary number. The obtained binary number will be equivalent to given octal number.

Examples

Question 1: Convert (41)8 to a binary number.

Solution:

Given number is (41)8

(41)8 = (4 * 81) + (1 * 8+0)

(9)

9

B N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer Science

= 32+1

= 33(Decimal number)

Now convert this decimal number to a binary number.

2 | 33 2 | 16 -- 1 2 | 8 -- 0 2 | 4 --0 2 | 2 -- 0 1 -- 0

The binary number is (100001)2

(41)8 = (100001)2

Question 2: Convert (27)8 to a binary number.

Solution:

Given number is (27)8

(27)8 = (2 * 8+1) + (7 * 80)

= 2 * 8 + 7 * 1

= 16 + 7

= 23(Decimal number)

Now convert this decimal number to a binary number.

2 | 23 2 | 11 -- 1 2 | 5 -- 1 2 | 2 --1 2 | 1 -- 0 2 | 0 -- 1

The binary number is (10111)2

(27)8 = (10111)2

(10)

10

B N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer Science

Question 3: Convert (10)8to a binary number.

Solution:

Given number is (10)8

(10)8 = (1 * 81) + (0 * 80)

= 1 * 8 + 0 * 1

= 8 + 0

= 8(Decimal number)

Now convert this decimal number to a binary number.

2 | 8 -- 0 2 | 4 --0 2 | 2 -- 0 1

The binary number is (1000)2

(10)8 = (1000)2

8. Conversion of Octal to Decimal

Question 1: Convert (5746)8 to decimal number

Solution:

The given number is (5746)8

(5746)8 = (5 * 83)+ (7 * 82) + (4 * 81) + (6 * 80)

=5 * 512 + 7 * 64 + 4 * 8 + 6 * 1

= 2560+448+32+6

= 3046

The equivalent decimal number for (5746)8 is 3046

(5746)8 = 3046

(11)

11

B N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer Science

Question 2: Convert (201)8 to decimal number

Solution:

The given number is (201)8

(201)8 = (2 * 82) + (0 * 81) + (1 * 80)

= 2 * 64 + 0 * 8 + 1 * 1

= 128+0+1

= 129

The equivalent decimal number for (201)8 is 129

(201)8 = 129

Question 3: Convert (6.1)8 to decimal number

Solution:

The given number is (6.1)8

(6.1)= (6 * 80) + (1 * 1/8)

= 6 * 1 + 1/8

= 6 + 1/8

= 6 + 0.125

= 6.125

The equivalent decimal number for (6.1)8 is 6.125

(6.1)8= 6.125

9. Conversion of Octal to Hexadecimal

Question 1: Convert (1002)8 to hexadecimal

Solution:

The given number is (1002)8

(1002)8 = (1 * 83)+ (0 * 82) + (0 * 81) + (2 * 80)

=1 * 512 + 0 * 64 + 0 * 8 + 2 * 1

(12)

12

B N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer Science

= 514(decimal number)

Now we convert the above decimal to hexadecimal 16 | 514

16 | 32 --2 2 -- 0

The hexadecimal number is 202

(1002)8 = (202)16

Question 2: Convert (100)8 to hexadecimal

Solution:

The given number is (100)8

(100)8 = (1 * 82) + (0 * 81) + (0 * 80)

= 1 * 64 + 0 * 8 + 0 * 1

= 64 + 0 + 0

= 64(decimal number)

Now we convert the above decimal to hexadecimal

16 | 64 16 | 4 --0 16 | 0 -- 4

The hexadecimal number is 40

(100)8 = (40)16

Question 3: Convert (15)8 to hexadecimal

Solution:

The given number is (15)8

(15)8 =(1 * 8+1) + (5 * 80)

= 1 * 8 + 5 * 1

= 8 + 5

= 13(decimal number)

Now we convert the above decimal to hexadecimal

13 is less than 16 so the equivalent hexadecimal number is D The hexadecimal number is D

(15)8 =(D)16

(13)

13

B N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer Science

Model-4: Conversion of Hexa Decimal Number System to Other base number system

Convert Hexadecimal to Binary

Convert hexadecimal to Decimal

Convert hexadecimal to octal

10.Convert Hexadecimal to Binary

Here it is not possible to convert it directly; we will convert hexadecimal to decimal then that decimal number is converted to binary.

Example:

1) (A1)16 2) (EE9)16 3) (FD654)16

Question 1: Convert (A2B)16 to a equivalent binary number

Solution:

Given hexadecimal number is (A2B)16

(A2B)16 = (A * 162) + (2 * 161) + (B * 160)

= (A * 256) + (2 * 16) + (B * 1)

= (10 *256) + 32 + 11

= 2560 + 43

= 2603(Decimal number)

Now we have to convert 2603 to binary

2 | 2603 2 |1301 -- 1 2 | 650 -- 1 2 | 325 -- 0 2 | 162 -- 1 2 | 81 -- 0 2 | 40 -- 1 2 | 20 -- 0 2 | 10 -- 0 2 | 5 -- 0 2 | 2 -- 1 2 | 1 -- 0 2 | 0 -- 1

The binary number is (101000101011)2

(14)

14

B N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer Science

Question 2: Convert (E)16 to a equivalent binary number

Solution:

Given hexadecimal number is E

(E)16 = E * 160

= E * 1

= E

=14(Decimal number)

Now we have to convert 14 to binary

2 |14 2 | 7 -- 0 2 | 3 -- 1 2 | 1 -- 1 2 | 0 -- 1

The binary number is (1110)2

(E)16 = (1110)2

Question 3: Convert (30)16 to a equivalent binary number

Solution:

Given hexadecimal number is (30)16

(30)16 = (3 * 161) + (0 * 160)

= 48 + 0

= 48(Decimal number)

Now we have to convert 48 to binary

2 | 48 2 | 24 -- 0 2 | 12 -- 0 2 | 6 -- 0 2 | 3 -- 0 2 | 1 -- 1 2 | 0 -- 1

The binary number is (110000)2

(15)

15

B N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer Science

11. Conversion of Hexadecimal to Octal

Question 1: Find the equivalent octal form of (C1)16

Solution:

Given hexadecimal number is (C1)16

(C1)16 = (C * 161) + (1 * 160)

= C * 16 + 1 * 1

=12 * 16 + 1

= 192 + 1

=193 (Decimal form)

Now we have to convert this decimal to octal

8 | 193 8 | 24 -- 1 8 | 3 -- 0 8 | 0 --3

The octal number is (301)8

(C1)16 = (301)8

Question 2: Find the equivalent octal form of (F)16

Solution:

Given hexadecimal number is (F)16

(F)16 = (F * 160)

= F * 1

= F

= 15(Decimal form)

Now we have to convert this decimal to octal

8 | 15 8 | 1 -- 7 8 | 0 -- 1

The octal number is (17)8

(16)

16

B N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer Science

Question 3: Find the equivalent octal form of (105)16

Solution:

Given hexadecimal number is (105)16

(105)16 = (1 * 162) + (0 * 161) + (5 * 160)

= 1*256 + 0 * 16 + 5 * 1

=256 + 0 +5

= 261(Decimal form)

Now we have to convert this decimal to octal

8 | 261 8 | 32 -- 5 8 | 4 -- 0 8 | 0 --4

The octal number is (405)8

(105)16= (405)8

12. Convert hexadecimal to Decimal:

Question 1: Convert (7B)16 into decimal number.

Solution:

Given hexadecimal number is (7B)16.

(7B)16 = 161 * 7 + 160 * B

= 16 * 7 + 1 * B

= 112 + 1 * 11

= 112 + 11

= 123

(17)

17

B N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer Science

Question 2: Convert (7E)16 into decimal number.

Solution:

Given hexadecimal number is (7E)16.

(7E)16 = 161 * 7 + 160 * E

= 16 * 7 + 1 * E

= 112 + 1 * 14

= 112 + 14

= 126

Answer is 126.

Question 3: Convert (CA)16 into decimal number.

Solution:

Given hexadecimal number is (CA)16.

(CA)16 = 161 * C + 160 * A

= 16 * C + 1 * A

= 16 *C + A

=16 * 12 +9

=192 + 9

=202

Answer is 202.

Question 4: Convert (20)16 into decimal number.

Solution:

Given hexadecimal number is (20)16.

(20)16 = 2 * 161 + 0 * 160

= 2 * 16 + 0 * 1

= 2 * 16 + 0 = 2 * 16 = 32

(18)

18

B N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer Science

Question 5: Convert (24)16 into decimal number.

Solution:

Given hexadecimal number is (24)16.

(24)16 = 2 * 161 + 4 * 160

= 2 * 16 + 4 * 1

= 2 * 16 + 4

= 32+ 4

=36

Answer is 36.

***********************************************************************************

Fraction conversions

Converting Binary fraction to decimal:

Example

Convert (11011.101)2 to decimal

24 23 22 21 20 . 2-1 2-2 2-3

= (1 x 24)+ (1 x 23)+ (0 x 22)+ (1 x 20)+ (1 x 2-1)+ (0 x 2-2)+ (1 x 2-3) = 16+8+0+1+0.5+0+0.125

= (25.625)10

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

Read the integers from top to bottom

(19)

19

B N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer Science

Example:

Convert (105.15)10 to binary

Let us convert 105 first.

(105)10 = (1101001)2

Let us convert (0.15)10

Multiply 0.15 by 2 0.30

Multiply 0.30 by 2 0.60

Multiply 0.60 by 2 1.20

Multiply 0.20 by 2 0.40

Multiply 0.40 by 2 0.80

Multiply 0.80 by 2 1.60

Reading the integers from top to bottom (0.15)10 = (0.001001)2

Final result (105.15)10 = (1101001.001001)2

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 fraction to decimal:

Example

Convert (23.25)8 to decimal

81 80 . 8-1 8-2

2 3 2 5

= (2 x 81)+ (3 x 80)+ (2 x 8-1)+ (5 x 8-2)

= 16+3+0.25+0.07812

(20)

20

B N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer Science

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 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

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

(21)

21

B N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer Science

Example

Convert (11100.1010)2 to hexadecimal equivalent.

0001 1100 . 1010

1 C . A

Answer : (1C.A)16

*********************************************************************************** BINARY ARITHMETIC

Binary Addition:

Adding Two Binary Numbers:

Adding binary number is similar to the addition of decimal numbers. While performing binary addition, start by adding the bits (digits) in one column at a time, from right to left as we do in the case of adding decimal numbers.

Rules of binary addition:

Rule-1: 0+0=0

Rule-2: 0+1=1

Rule-3: 1+0=1

Rule-4: 1+1=0, and carry 1 to the next most significant bit.

Let us consider the following example: 0001010

+ 0100100 --- 0101110

Example-2

11 ---Carry 1011

+ 0001

--- 1100

***********************************************************************************

Binary Subtraction:

Subtracting two binary numbers:

The binary subtraction will be performed on the two binary numbers.

Rules of binary subtraction:

Rule-1: 0-0=0

(22)

22

B N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer Science

Rule-3: 1-1=0

Rule-4: 0-1=1, and borrow 1 from most significant bit.

Consider the following examples:

Ex-1:

1011

- 1001

--- 0010

Ex-2: 11 222

1000101 Minuend - 0011000 Subtrahend ---

0101101 Difference ---

***********************************************************************************

Subtraction Two Binary Numbers Using Two’s Complement:

Calculate 1011-1001 using two’s complement method.

Sol:

Find the two’s complement of the subtrahend.

Subtrahend=1001

One’s complement of subtrahend = 0110.

Two’s complement of subtrahend = 0110+1=0111(here add 1 with 0110).

Add the minuend and the two’s complement of the subtrahend.

1011

+ 0111

---

1 0010

---

Now discard the carry from the last bit. Hence the result is 0010.

(23)

23

B N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer Science

Multiplying two Binary Numbers:

Binary numbers are multiplied in the same manner as we multiply two decimal numbers. The rules of multiplications of binary numbers are the same as that of decimal numbers that is:

Rule-1: 0 x 0 = 0

Rule-2: 0 x 1 = 0

Rule-3: 1 x 0 = 0

Rule-4: 1 x 1 = 1

Note that since binary operates in base 2, the multiplication rules we need to remember are those that involve 0 and 1 only. As an example of binary multiplication we have 101 times 11,

101 x11

First we multiply 101 by 1, which produces 101. Then we put a 0 as a placeholder as we would in decimal multiplication, and multiply 101 by 1, which produces 101.

101 x11 101

1010 <-- the 0 here is the placeholder

The next step, as with decimal multiplication, is to add, the results from our previous step indicates that we must add 101 and 1010, the sum of which is 1111.

101 x11 101 1010 1111

***********************************************************************************

Dividing two Binary Numbers:

Binary division Binary division is similar to dividing two decimal number.

For example consider the division of 1011 into 11.

11 R=10 11 )1011 -11 101 -11

10 <-- remainder, R

(24)

24

B N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer Science

11 x 11 11 11

1001 <-- product of 11 and 11

1001 + 10

1011 <-- sum of product and remainder

The sum is equal to our initial dividend, therefore our solution is correct.

***********************************************************************************

Binary Representation of Integers

Binary number can be represented only by using 0’s and 1’s, but cannot use the sign (-) to denote the negative number or sign (+) to denote the positive number. So it must be either 0 or 1. There are three methods to represent binary number. They are

(i) Sign and magnitude method (ii) One’s complement method (iii) Two’s complement method

Sign and magnitude method

In this method, first bit is considered as a sign bit. Here positive number starts with 0 and negative number starts with 1.

Example

25

25/2 = 12 1

12/2 = 6 0

6/2 = 3 0

3/2 = 1 1

1/2 = 0 1

So the binary number is (11001)2. If we take the size of the word is 1 byte, then the number 25

will be represented as 00011001

Suppose, if the number is -25, and then it will be represented as (10011001)2

One’s Complement Method

(25)

25

B N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer Science

Example

(i) Represent 86 in one’s complement method (I byte representation)

86/2 = 43 0 43/2 = 21 1 21/2 = 10 1

10/2 = 5 0

5/2 = 2 1

2/2 = 1 0

1/2 = 0 1

The binary number is 1010110

1 byte representation of number 86 is 01010110

(ii) Represent -55 in one’s complement method (I byte representation)

55/2 = 27 1 27/2 = 13 1

13/2 = 6 1

6/2 = 3 0

3/2 = 1 1

1/2 = 0 1

The binary number is 110111 1 byte representation is 00110111

The given number is negative; hence we need to calculate one’s complement

One’s complement of 00110111 is 11001000 (convert 1 into 0 and 0 into 1)

Thus, the 1 byte representation of number -55 is 11001000.

Two’s Complement method

In this method, the positive number is represented as the binary number. If the number is negative, then we need to calculate two’s complement of a binary number. The two’s complement of a binary number is calculated by adding 1 to its one’s complement.

Example

(i) Represent 87 in two’s complement method (I byte representation)

87/2 = 43 1 43/2 = 21 1 21/2 = 10 1

10/2 = 5 0

5/2 = 2 1

2/2 = 1 0

1/2 = 0 1

The binary number is 1010111

(26)

26

B N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer Science

(ii) Represent -54 two’s complement method (I byte representation)

54/2 = 27 0 27/2 = 13 1

13/2 = 6 1

6/2 = 3 0

3/2 = 1 1

½ = 0 1

The binary number is 110110

Hence, the 1 byte representation is 00110110

The given number is negative; hence we need to calculate two’s complement.

One’s complement of 00110110 is 11001001 (convert 1 into 0 and 0 into 1)

Add 1 to one’s complement

1

11001001 (1+1=2, binary equivalent =11)

+ 1 --- 11001010

Thus, 1 byte representation of number -54 is 11001010

(iii) Represent -77 two’s complement method (I byte representation)

77/2 = 38 1 38/2 = 19 0

19/2 = 9 1

9/2 = 4 1

4/2 = 2 0

2/2 = 1 0

1/2 = 0 1

The binary number is 1001101

Hence, 1 byte representation is 01001101.

Since the given number is negative, we need to calculate two’s complement.

One’s complement of 01001101 is 10110010

10110010

+ 1 --- 10110011

Thus, 1 byte representation of number -77 is 10110011.

(27)

27

B N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer ScienceB N aresh, Lecturer in BVRICE. Dept., of Computer Science

Computer Codes

Computers and digital circuits process information in the binary format. Each character is assigned 7 or 8 bit binary code to indicate its character which may be numeric, alphabet or special symbol. Example - Binary number 1000001 represents 65(decimal) in straight binary code, alphabet A in ASCII code and 41(decimal) in BCD code.

Types of codes

BCD (Binary-Coded Decimal) code:

• Four-bit code that represents one of the ten decimal digits from 0 to 9.

• Example - (37)10 is represented as 0011 0111 using BCD code, rather than (100101)2 in straight

binary code.

• Thus BCD code requires more bits than straight binary code.

• Still it is suitable for input and output operations in digital systems.

Note: 1010, 1011, 1100, 1101, 1110, and 1111 are INVALID CODE in BCD code.

ASCII (American Standard Code Information Interchange) code :

• It is 7-bit or 8-bit alphanumeric code.

• 7-bit code is standard ASCII supports 127 characters.

• Standard ASCII series starts from 00h to 7Fh, where 00h-1Fh are used as control characters and

20h-7Fh as graphics symbols.

• 8-bit code is extended ASCII supports 256 symbols where special graphics and math's symbols

are added.

• Extended ASCII series starts from 80h to FFh.

EBCDIC (Extended Binary Coded Decimal Interchange Code) code

• 8-bit alphanumeric code developed by IBM, supports 256 symbols.

• It was mainly used in IBM mainframe computers.

Gray code

• Differs from leading and following number by a single bit.

• Gray code for 2 is 0011 and for 3 is 0010.

• No weights are assigned to the bit positions.

• Extensively used in shaft encoders.

Excess-3 code

• 4-bit code is obtained by adding binary 0011 to the natural BCD code of the digit.

• Example - decimal 2 is coded as 0010 + 0011 = 0101 as Excess-3 code.

• It not weighted code.

• Its self-complimenting code means 1's complement of the coded number yields 9's complement

of the number itself.

• Used in digital system for performing subtraction operations.

***********************************************************************************

Important Questions

Define number system and explain its types.

Define number system and explain number conversions with examples.

Explain about the fraction conversions with suitable examples.

How to represent the integers in binary.

References

Related documents

- Run the alternator at its rated speed, and adjust the exciter field current using the rheostat to obtain the rated output current in the short-circuit connections.. Note :

Thus, while only around 5% of residential properties in Australia are clearly exposed to riverine flood risks which results in very high premiums, the insurance market is unable

Solution: This is a square prism with a square pyramid on top. Find the volume of each separately and then add them together to find the total volume. First, find the height of

For the detection of AMR determinants, the results were interpreted as follows: (i) a positive penA Asp345del reaction (indicating the presence of a mosaic penA allele) without or

 こうした“Shelley’s defects”は Leigh Hunt の認めるところでもあった。 しかしその一方で彼は、この詩の批評において、政治詩人としての Shelley に 対

Based on their behaviour in simple examples and their success in numerical simulations, it is believed that the maximal and CMC slicing conditions will in general produce

The parasitoid Venturia canescens (Gravenhorst) (Hymenoptera: Ichneumonidae) did not enter the bags, but located host larvae inside the jute bags and parasitized rice moths

The complexity of such an analysis is driven by the system scenario (SNR, channel model, antennas, modulation, channel code, etc.), the receiver parameters (demapper clipping factor