Docsity

number system in computers, Slides of Computer Science

Partial preview of the text

Download number system in computers and more Slides Computer Science in PDF only on Docsity!

Number

Representation

Number System :: The Basics

n We are accustomed to using the so-called

decimal number system

¨ Ten digits :: 0,1,2,3,4,5,6,7,8,

¨ Every digit position has a weight which is a

power of 10

¨ Base or radix is 10

Example:

234 = 2 x 10

2

+ 3 x 10

1

+ 4 x 10

0

250.67 = 2 x 10

2

+ 5 x 10

1

+ 0 x 10

0

+ 6 x

  • 1

+ 7 x 10

  • 2

Positional Number Systems (General)

Decimal Numbers:

v 10 Symbols {0,1,2,3,4,5,6,7,8,9}, Base or Radix is 10 v 136.25 = 1 ´^ **10 2

  • 3** ´^ **10 1
  • 6** ´^ **10 0
  • 2** ´^ 10

- 1 + 3 ´^ 10 - 2

Positional Number Systems (General)

Decimal Numbers:

v 10 Symbols {0,1,2,3,4,5,6,7,8,9}, Base or Radix is 10 v 136.25 = 1 ´^ **10 2

  • 3** ´^ **10 1
  • 6** ´^ **10 0
  • 2** ´^ 10

- 1 + 3 ´^ 10 - 2

Binary Numbers:

v 2 Symbols {0,1}, Base or Radix is 2 v 101.01 = 1 ´^ **2 2

  • 0** ´^ **2 1
  • 1** ´^ **2 0
  • 0** ´^ 2

- 1 + 1 ´^ 2 - 2

Positional Number Systems (General)

Decimal Numbers:

v 10 Symbols {0,1,2,3,4,5,6,7,8,9}, Base or Radix is 10 v 136.25 = 1 ´^ **10 2

  • 3** ´^ **10 1
  • 6** ´^ **10 0
  • 2** ´^ 10

- 1 + 3 ´^ 10 - 2

Binary Numbers:

v 2 Symbols {0,1}, Base or Radix is 2 v 101.01 = 1 ´^ **2 2

  • 0** ´^ **2 1
  • 1** ´^ **2 0
  • 0** ´^ 2

- 1 + 1 ´^ 2 - 2

Octal Numbers:

v 8 Symbols {0,1,2,3,4,5,6,7}, Base or Radix is 8 v 621.03 = 6 ´^ **8 2

  • 2** ´^ **8 1
  • 1** ´^ **8 0
  • 0** ´^ 8

- 1 + 3 ´^ 8 - 2

Hexadecimal Numbers:

v 16 Symbols {0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F}, Base is 16 v 6AF.3C = 6 ´^ **16 2

  • 10** ´^ **16 1
  • 15** ´^ **16 0
  • 3** ´^ 16

- 1 + 12 ´^ 16 - 2

Binary-to-Decimal Conversion

n Each digit position of a binary number has a weight

¨ Some power of 2

n A binary number:

B = b

n- 1

b

n- 2

…..b

1

b

0

. b

  • 1

b

  • 2

….. b

  • m Corresponding value in decimal: D = S b i 2 i i = - m n- 1

Decimal to Binary: Integer Part

nConsider the integer and fractional parts separately.
nFor the integer part:

nRepeatedly divide the given number by 2, and go on accumulating the remainders, until the number becomes zero. nArrange the remainders in reverse order. 2 89 2 44 1 2 22 0 2 11 0 2 5 1 2 2 1 2 1 0 0 1 Base NumbRem (89) 10 = (1011001) 2

Decimal to Binary: Integer Part

nConsider the integer and fractional parts separately.
nFor the integer part:

nRepeatedly divide the given number by 2, and go on accumulating the remainders, until the number becomes zero. nArrange the remainders in reverse order. 2 89 2 44 1 2 22 0 2 11 0 2 5 1 2 2 1 2 1 0 0 1 Base NumbRem (89) 10 = (1011001) 2 2 66 2 33 0 2 16 1 2 8 0 2 4 0 2 2 0 2 1 0 0 1 (66) 10 = (1000010) 2

Decimal to Binary: Fraction Part nRepeatedly multiply the given fraction by 2. nAccumulate the integer part (0 or 1). nIf the integer part is 1, chop it off. nArrange the integer parts in the order they are obtained.

Example: 0.

.634 x 2 = 1. .268 x 2 = 0. .536 x 2 = 1. .072 x 2 = 0. .144 x 2 = 0. : : (.634) 10 = (.10100……) 2

Decimal to Binary: Fraction Part nRepeatedly multiply the given fraction by 2. nAccumulate the integer part (0 or 1). nIf the integer part is 1, chop it off. nArrange the integer parts in the order they are obtained.

Example: 0.

.634 x 2 = 1. .268 x 2 = 0. .536 x 2 = 1. .072 x 2 = 0. .144 x 2 = 0. : : (.634) 10 = (.10100……) 2

Example: 0.

.0625 x 2 = 0. .1250 x 2 = 0. .2500 x 2 = 0. .5000 x 2 = 1. (.0625) 10 = (.0001) 2

Hexadecimal Number System

n A compact way of representing binary numbers
n 16 different symbols (radix = 16)
0 à 0000 8 à 1000
1 à 0001 9 à 1001
2 à 0010 A à 1010
3 à 0011 B à 1011
4 à 0100 C à 1100
5 à 0101 D à 1101
6 à 0110 E à 1110
7 à 0111 F à 1111

Binary-to-Hexadecimal

Conversion

n For the integer part,

¨ Scan the binary number from right to left
¨ Translate each group of four bits into the
corresponding hexadecimal digit
n Add leading zeros if necessary

n For the fractional part,

¨ Scan the binary number from left to right
¨ Translate each group of four bits into the
corresponding hexadecimal digit
n Add trailing zeros if necessary

Hexadecimal-to-Binary

Conversion

n Translate every hexadecimal digit into its 4 - bit binary equivalent n Examples:

(3A5)

16

2

(12.3D)

16

2

16

2

Unsigned Binary Numbers

n An n-bit binary number

B = b

n- 1

b

n- 2

…. b

2

b

1

b

0

n 2

n

distinct combinations are possible, 0 to 2

n

n For example, for n = 3, there are 8 distinct

combinations

n Range of numbers that can be represented

n=8 è 0 to 2

8

  • 1 (255)

n=16 è 0 to 2

16

  • 1 (65535)

n=32 è 0 to 2

32

  • 1 (4294967295)