Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
1 views

Computer Codes

A brief explanation to the computer coding scheme
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Computer Codes

A brief explanation to the computer coding scheme
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

NUMBER SYSTEM

Application of Information and Communication


Technologies

Faculty of Computing and Information Technology (FCIT)


University of the Punjab, Lahore, Pakistan.
Learning Objectives
1. Distinguish among categories of numbers
2. Describe positional notation
3. Convert numbers in other bases to base 10
4. Convert base-10 numbers to numbers in
other bases
5. Describe the relationship between bases 2, 8,
and 16
6. Explain the importance to computing of bases
that are powers of 2

2
Number System
• Mainly there are two types of number
systems
• Non-Positional Number System
• Use fingers for counting. Use stones
• Does the direction matter?
• Positional Number System
• Position matters
Non-positional Number System
• Use symbols such as I for 1, II for 2, III for 3, etc

• Each symbol represents the same value regardless of its


position in the number

• Difficult to perform arithmetic with such a number system


Positional Number System
• Value of each digit is determined by:
• The digit itself
• The position of the digit in the number
• The base of the number system

Base = total number of digits in the number


system
Decimal Number system (positional system)
Positional Notation
642 in base 10 positional notation is:

6 x 102 = 6 x 100 = 600


+ 4 x 101 = 4 x 10 = 40
+ 2 x 10º = 2 x 1 = 2 = 642 in base 10

The power indicates


the position of
This number is in the number
base 10
Positional Notation
R is the base
of the number
As a formula:

dn * Rn-1 + dn-1 * Rn-2 + ... + d2 * R1 + d1 * R0

n is the number of d is the digit in the


digits in the number ith position
in the number

642 is 6 * 102 + 4 * 10 + 2 * 1
Positional Notation
• What if 642 has a base of 13?

6 x 132 = 6 x 169 = 1014


+ 4 x 131 = 4 x 13 = 52
+ 2 x 13º = 2 x 1 = 2
= 1068 in base 10

• 642 in base 13 is equivalent to 1068 in base 10


Binary Number system
Binary counting
Binary –Decimal Equal
Why Binary in Computers?
o Binary positional systems have great advantages
over decimals in electronic computing
o Circuits in computers have billions of transistors
that can turn on and off
o Two reasons computer use binary
o Two clearly distinct states that provide a safe range for
reliability.
o Least amount of necessary circuitry, which results in
the least amount of space, energy consumption, and
cost.
Why Binary in Computers?
● It is easy for machines to store electrical signals as ON or OFF
● Binary math is easier for computers than anything else
● Binary numbers help in digital electronic circuits using logic gates
○ Logic gates are the basic building blocks of any digital system
○ Common logic gates are AND, OR, NOT, XOR, NOR, NAND
Binary
oRecall, in decimal each position of digital is
multiplied case by base ten (10)
o273 = 2*102+7*101+3*100
o543.21 = 5*102+4*101+3*10+2*10-1+1*10-2
oSimilarly binary equivalence is
o5 = 101 = 1*22+0*21+1*20= 4+0+1
o26 = 11010= 1*24+1*23+0*22+1*21+0*20=
16+8+0+2+0
Binary Number
oBinary number is generally much longer than its
corresponding decimal number
o256,058 = 111 11010 00001 11010
oReason: binary system has only two possibilities
oIn other words, binary digit carries less information
than in decimal digit
Octal Number System
oThe numbers with base 8 are called octal
o0, 1, 2, 3, 4, 5, 6, 7
oThere is no such thing as 8 and 9
oWe count the same way as we do for decimal, but
we stop at 7
Octal-Decimal
Octal Number System
oWe count the same way as we do for decimals,
but we stop at 7
oMeans, we will have 10 after 7.
oSimilarly, 20 after 17
o(35)10=(43)8
Why we are discussing Octal
oThe fact that there is a short cut method to
convert binary number into octal
oMethod: make group of 3 digits start from right
to left
Hexadecimal Number System
oHexadecimal numbers is also important in
computers
oHexadecimal has based 16 and basic symbols
are
o 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
o A is 10 and F is 15
Decimal-Hexadecimal
Why Hexadecimal?
• (43)16 = 4x161+3x160 = 64+3 = (67)10
• (A5B)16 = Ax162+5x161+Bx160 = 10*256+5x16+11 = 2560+80+11 =
(2651)10

oThere is a shortcut method to convert binary into


hexadecimal
Decimal to Any Base
For converting a given decimal number to any base, we need to divide the number with
the target base. Lets see how to convert from Decimal to Binary
Decimal to Hexadecimal
(423)10 = ( ? )16
Any Base to Decimal?
We can express any given n digit number of any base as

(642)10 = 6 * 102 + 4 * 101 + 2 * 100

(1011)2 = 1 * 23 + 0 * 22 + 1 * 21 +
1 * 20
(A12)16 = A * 162 + 1 * 161 + 2 *
160
Binary to Hexa and Hexa to Binary?

(BC11)16 = ( )2

(1110011101)2 = ( )16
How many numbers can be represented
using different number of bits?
1 bit 2 bits 3 bits 4 bits
Computer Arithmetic
Binary Addition

oIt’s a key for binary subtraction,


multiplication, division
oFour Rules Case A + B Sum Carry
1 0+0 0 0
2 0+1 1 0
3 1+0 1 0
4 1+1 0 1
Binary Addition

oExample
Binary Addition

oExample
Binary Subtraction

oIt’s a key for binary subtraction,


multiplication, division
oFour Rules Case A - B Subtra Carry
ct
1 0-0 0 0
2 1-0 1 0
3 1-1 0 0
4 0-1 0 1
Binary Subtraction

oExample
Binary Subtraction

oExample
Issues in Binary Subtraction

o The classical subtraction (discussed above)


o Works when we subtract small number from
large number (27-9)
o However, it does not work when we subtract a
large number from small number
o Alternatively, we use two methods
o 1’s complement
o 2’s complement
Negative Binary Number Representation
• Sign-magnitude Representation

• One’s Complement: Flip the bits to get the negative number


representation

+53 = 00110101
-53 = 11001010

• Two’s Complement: Find One’s complement and then add 1 to


get the negative number representation

+53 = 00110101
-53 = 11001011
Issues in Binary Subtraction

o1’s complement is obtained by replacing 0’s


with 1’s and 1’s with 0’s
o For example, 1’s complement of 10110 is 01001
o2’s Complement
o Write the number in binary (say, 10001)
o Take 1’s complement (01110)
o Add 1 to it (01111)
Subtraction using 2’s complement

o 2’s Complement
o First of all 2's complement of the subtrahend (In a-b,
b is subtrahend) is found
o Then it is added to minuend (In a-b, a is minuend)
o If the final carry over of the sum is 1, it is dropped
and the result is positive
o If there is no carry, the 2's complement of the sum
will be the result and it is negative
Signed-magnitude
Two’s Complement for adding +3
number for adding two
and -3
number (+3 and -3) using
4 bits representation

One’s Complement for


adding +3 and -3

You might also like