You are on page 1of 5

The Hardware World

Given 1 bit, how many distinct combinations of 1 bit exist?


Week: Lecture Date: 06 12/03/2012
Ans: Ans:

Given 4 bits, how many distinct combinations of 4 bits exist?


Ans: Ans:

Course: Computer Fundamental Instructor: Dr. Arif Mushtaq Topic: Number Systems-1 Systems-

Given n bits, how many distinct combinations of n bits exist?


Ans: Ans:

The Hardware World


A bit can take the values 0 or 1, thus it can describe 2 possibilities or can uniquely identify 2 things. Two bits can take the value 00, 01, 10, 11, thus it can describe four 22 possibilities or 2 can uniquely identify 4 things. n bits can encode 2 power n (2n possibilities).

The Hardware World


Assume there are 400 students in this campus. If every student is to be assigned a unique bit pattern, what is the minimum number of bits required to do this? How many more students can be admitted to this campus without requiring additional bits for each students unique bit pattern?

The Hardware World


What is the minimum number of bits required to represent the last four digits of your roll number? What is the minimum number of bits required to represent Pakistans population assuming it to be 160 million?

Information Representation
There are two types of information representation.
External representation Internal representation

External Representation:- of information is the way Representation:that how the information is represented by the humans and the way it is entered at a keyboard or displayed on a printer or screen. Internal Representation:- of information is the way Representation:it is stored in the memory of a computer or passed to any device of computer.

Number Systems
The on and off states of the capacitors in RAM can be thought of as the values 1 and 0, respectively. Therefore, thinking about how information is stored in RAM requires knowledge of the binary (base 2) number system. Lets review the decimal (base 10) number system first.

Number Systems
Decimal Number System
Base is 10 or D or Dec Ten symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Each place is weighted by the power of 10 Example: 123410 or 1234D = 1 x 103 + 2 x 102 + 3 x 101 + 4 x 100 = 1000 + 200 + 30 + 4
$1,000 $100 $10 $1

The Decimal Number System


The decimal number system is a positional number system. Example:

Conversion between Decimal and Binary


Binary Number System
Base is 2 or b or B or Bin Two symbols: 0 and 1 Each place is weighted by the power of 2 Example: Example: 10112 or 1011 B = 1 x 23 + 0 x 22 + 1 x 21 + 1 x 20 = 8 + 0 + 2 +1 = 1110
11 in decimal number system is 1011 in binary number system

5 6 2 1
103 102 101 100

1 X 100 2 X 101 6 X 102 5 X 103

= 1 = 20 = 600 = 5000

Conversion between Decimal and Binary


Conversion from decimal number system to binary system
Question: represent 3410 in the binary number system Answer: using the divide-by-2 technique repeatedly
34
div-by-2

Converting decimal to binary


Example: 162:
162 / 2 81 / 2 40 / 2 20 / 2 10 / 2 5/2 2/2 1/2 = 81 = 40 = 20 = 10 =5 =2 =1 =0 rem 0 rem 1 rem 0 rem 0 rem 0 rem 1 rem 0 rem 1

17
div-by-2

8
div-by-2

4
div-by-2

2
div-by-2

1
div-by-2

Remainder

If we write the remainder from right to left :


3410 1 x 25 + 0 x 24 + 0 x 23 + 0 x 22+ 1x 21 1000102

+ 0 x 20

So, 16210 = 101000102

Some Exercises
13D = (?) B 1101B 23D = (?) B

Converting decimal to binary


Conversion from binary number system to decimal system
Example: check if 1000102 is 3410 using the :weights appropriately

1000102 1 x 25 + 0 x 24 + 0 x 23 + 0 x 22+ 1 x 21 + 0 x 20

32 +

+ 0

+ 2

+ 0

3410

72D = (?) B

Some Exercises
Ex: 0101B
Bit 4 23 = 8

Binary Arithmetic on Integers


Addition
Bit 1 20 = 1

(?)D
Bit 3 22 = 4 Bit 2 21 = 2

1 4

0 +

1 1 = 5D

Ex: 1100B

(?)D

a 0 0 1 1

b 0 1 0 1

a+b 0 1 1 10
Carry bit

1 1 0 0 8 4 2 1 = 12D

Ex: 0101 1100B


0
128

(?)D
1
16

Example: find binary number of a + b If a = 13D , b = 5D 13D + 5D 18D

1 1 +

1 1 0 1b 0 1 0 1b 1 0 0 1 0b 1 1 1

1
64

0
32

1
8

1
4

0
2

0
1

If a = 15D, b = 10D

= 92D

15D + 10D 25D

1 1 1 1b + 1 0 1 0b 1 1 0 0 1b

Binary Arithmetic on Integers (cont.)


Multiplication
a 0 0 1 1 b 0 1 0 1 axb 0 0 0 1

Working with Large Numbers


0101000010100111 = ?
Humans cant work well with binary numbers; there are too many digits to deal with. Memory addresses and other data can be quite large. Therefore, we sometimes use the hexadecimal number system.

Example: if a = 100001b , b = 101b , find a x b 1 0 0 0 0 1b x 1 0 1b 100001 0000000 10000100 1 0 1 0 0 1 0 1b 165D 33D 5D

Hexadecimal Number System


Hexadecimal Number System
Base = 16 or H or Hex 16 symbols: { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A(=10), B(=11), C(=12), D(=13), E(=14), F(=15)}

Hexadecimal Number System


Decimal to Hexadecimal
Example: Example: (829)10 = (? )16
Divide-by-16 829 / 16 51 / 16 3 / 16 Quotient 51 3 0 Remainder 13 3 3

Repeated division by 16

Similar in principle to generating binary codes

Hexadecimal to Decimal
(an-1an-2a1a0)16 = (an-1 x 16n-1 + an-2 x 16n-2 + + a1 x 161 + a0 x 160 )D Example: (1C7)16 = (1 x 162 + 12 x 161 + 7 x 160 )10
= (256 + 192 + 7)10 = (455)10

Stop, since quotient = 0

Hence, (829)10 = (3313)16

(33D)16

Hexadecimal Conversions
Hexadecimal to Binary
Expand each hexadecimal digit to 4 binary bits.
Example: (E29)16 = (1110 | 0010 | 1001)2

Example of Equivalent Numbers


Binary: 1 0 1 0 0 0 0 1 0 1 0 0 1 1 12 Decimal: 2064710 Hexadecimal: 50A716 Notice how the number of digits gets smaller as the base increases.

Binary to Hexadecimal
Combine every 4 bits into one hexadecimal digit
Example: (0101 | 1111 | 1010 | 0110)2 = (5FA6)16

Practice Questions
1) Convert the following binary numbers to decimal numbers:
(a) (b) (c) (d) 0011 B 0101 B 0001 0110 B 0101 0011 B

Practice Questions
3) Convert the following binary/dec numbers to hexadecimal numbers:
(a) (b) (c) (d) (a) (b) (c) 0011 B 0101 B 0001 0110 B 0101 0011 B 21 D 731 D 1,023 D

2) Convert the following decimal numbers to binary:


(a) (b) (c) 21 D 731 D 1,023 D

4.) Perform the following binary additions and subtractions. Show your work without using decimal numbers during conversion.
(a) (b) 111 B + 101 B 1001 B + 11 B

Information Representation (Summary)


Externally, computers do use decimal digits, sign/magnitude notations, and the familiar 26character alphabets. However, virtually every computer ever build stores data- numbers, letters, graphics-internally using the binary numbering system.
Memory

Information Representation (Summary)


A bit is a single binary digit (a 1 or 0). A byte is 8 bits A word is 32 bits or 4 bytes Long word = 8 bytes = 64 bits Quad word = 16 bytes = 128 bits Programming languages use these standard number of bits when organizing data storage and access. What do you call 4 bits? (hint: it is a small byte)

A C

01000001

A
Screen

Keyboard External Representation Internal Representation

You might also like