0% found this document useful (0 votes)
45 views

Fundamentals of Computer Programming: Jehangir Arshad Meo

1011011 - 10010 = 1001001 Example 2: 1101 − 1001 = 100:

Uploaded by

Alpha Romeo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

Fundamentals of Computer Programming: Jehangir Arshad Meo

1011011 - 10010 = 1001001 Example 2: 1101 − 1001 = 100:

Uploaded by

Alpha Romeo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 26

Fundamentals of

Computer Programming
Jehangir Arshad Meo

Lecture 3

Mechanical Engineering Department

COMSAT Institute of Information Technology, Sahiwal


Number Systems
 Decimal Number System

 Binary Number System

 Octal Number System

 Hexadecimal Number System


Decimal Number System
Base is 10

Use 10 symbols 0,1,2,3,4,5,6,7,8,9

Each place is weighted by the power of 10

E.g. 4,309,108 etc


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:
10112 or 1011 B
Binary Representation of numbers
Binary means 2 bit number system [0 , 1].

Bit is the smallest unit of data.

1 bit = a single digit, either 1 or 0


8 bits = 1 byte , combination of 1's & 0's # of Comb Binary Decimal
1024 Bytes = 1 KB (kilobyte)
1024 Kilobytes = 1 MB (megabyte) 1 00 0
1024 Megabytes = 1 GB (gigabyte)
2 01 1

2 Bits represent 22 = 4 3 10 2

4 11 3
Converting Decimal to Binary
 For example convert 13 to Base 2

2 13

2 6 ---- 1
2 3 ---- 0

1 ---- 1

(1101)2
Converting decimal to binary
Example: 162:

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

So, 16210 = 101000102


Some

Exercises
13D = (?) B
1101B

23D = (?) B 10111B

1001000B
72D = (?) B
Some Exercises
59D = (?) B 111011B

10010001 B
145 D = (?) B
Conversion from binary number system to
decimal system
Exercises: Binary to decimal conversion
Class Room Practice:
Decimal to Binary Conversion:

 (1458)10 = (10110110010)2
 (66697)10 = (10000010010001001)2
 (654785 )10 = (10011111110111000001)2

Binary to Decimal Conversion:

(110101)2 = (53)10
(10001011)2 = (139)10
(100011110110)2 = (2294)10

Link (Must Visit):


http://www.binaryhexconverter.com/decimal-to-binary-converter
http://www.binaryhexconverter.com/binary-to-decimal-converter
Hexadecimal Number System
Base is 16 or ‘Hex’ or ‘H’

16 symbols: {0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F}

Each place is weighted by the power of 16

24 = 16 , so 4 bits are required to represent Hexadecimal


Number

Example:
(3AB)H
Conversion from Decimal to Hexadecimal

Same as that of Decimal to Binary

Repeatedly divide by 16

16 93

5 ---- D
Conversion from Hexadecimal to Decimal

(3AB4)H to Base 10

(3AB4) = 3x163+10x162+11x161+4x 160


= 15028
Conversion from and conversion to decimal number
systems:
In conversion from Decimal to any number system,
you have to divide the value by the base of that
number system, in which you desire to convert decimal
value.

In conversion from any number system to Decimal,


you have to multiply each value by the base in the
power of number’s place, of that number system from
which you are converting to decimal.
Hexadecimal to Binary (Direct Method)
Hexadecimal to Binary
Expand each hexadecimal digit to 4 binary bits.
Example: (E29)16 = (1110 | 0010 | 1001)2

Binary to Hexadecimal
Combine every 4 bits into one hexadecimal digit
Example: (0101 | 1111 | 1010 | 0110)2 = (5FA6)16
Octal Number System
Base is 8
8 symbols: {0,1,2,3,4,5,6,7}
Each place is weighted by the power of 8
 So how many bits required to represent an octal number?????

Example:

(345)8
Conversion from Decimal to Octal
Repeatedly divide by 8

Conversion from Octal to Hexadecimal


The conversion is made in two steps using binary as an intermediate
base. Octal is converted to binary and then binary to hexadecimal,
grouping digits by fours, which correspond each to a hexadecimal
digit.

For instance, convert octal 1057 to hexadecimal


To binary:
1 0 5 7
001 000 101 111
then to hexadecimal:
0010 0010 1111
2 2 F
Therefore, 10578 = 22F16.
Number System:
Octal to Binary
Expand each octal digit to 3 binary bits.
Example: (725)8 = (111 | 010 | 101)2

Binary to Octal
Combine every 3 bits into one octal digit.
Example: (110 | 010 | 011)2 = (623)8
Some important Conversions to Remember
Base 10 Base 2 Base 16
0 0 0
1 1 1
2 10 2
3 11 3
4 100 4
5 101 5
6 110 6
7 111 7
8 1000 8
9 1001 9
10 1010 A
11 1011 B
12 1100 C
13 1101 D
14 1110 E
15 1111 F
Signed number representation
In ordinary arithmetic, a negative number is
indicated by a minus sign and a positive number by a
plus sign.

In computers, the convention is to represent the sign


with an extra bit placed in the leftmost position (the
sign bit).

sign bit 0 for positive and 1 for negative.

22
Decimal to Binary :
To convert decimal fractions to binary fraction, continually multiply
fraction by base (2). The integer parts of the results give the digits from
right to left.
0.6875
2
1.375
2
 0.750  0.10112
2
1.500
2
1.000 23
Example

12.3910
Separate the integer and fraction part
0.39
Convert the integer part
* 2
1210 = 11002
0.78
Convert the fractional part
* 2
0.3910 = 01102 1.56
* 2
12.3910 = 1100.01102
1.12
* 2
0.24
24
Binary addition:
Example 1:
0+0=0
1+0=1
0+1=1
1 + 1 = 10
1 + 1 + 1 = 11
Example 2: 1 1 1 carry
1001101 1001001 value 1
+0010010 + 0011001 value 2
1011111 1100010 sum
Binary Subtraction:
Example 1:

1011011 − 10010 = 1001001:

You might also like