0% found this document useful (0 votes)
21 views36 pages

Week 3&4 NumberSystems

Uploaded by

kinzazahir12
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)
21 views36 pages

Week 3&4 NumberSystems

Uploaded by

kinzazahir12
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/ 36

Number System

(Different Ways To Say How


Many)
Fall 2022

INTRODUCTION TO INFORMATION AND COMMUNICATION


TECHNOLOGIES
Outline 2

4
24/10/202
 Numeral System
 Decimal System
 Binary System
 Octal System
 Hexadecimal System
 Digit and Positions
 Bits, Bytes & Words
 Conversions
 Negative Numbers
Numeral System 3

4
24/10/202
 A Numeral System is a writing-system for expressing numbers, a mathematical
notation for representing numbers of a given set, using symbols in a consistent
manner.
 Ideally, a numeral system will:
 Represent a useful set of numbers (integers, or rational numbers)
 Give every number represented a unique representation (or a standard representation)
 Reflect the algebraic and arithmetic structure of the numbers.
Base/Radix of Numeral System 4

4
24/10/202
 The number of distinct symbols that can be used to represent numbers in that
system.
 For example, the base for the ‘decimal numerical symbol is 10’, as we can use the
ten symbols 0,1,2,…,9 to represent numbers in this system.

This means that the same number will


have different representations in
different systems. So, ‘101’ means a
hundred and one in decimal, and five,
in binary; while 5 means five in decimal
but is invalid in binary as the symbol
‘5’ is not allowed in binary.
Decimal Number System 5
 The decimal numeral system (base ten or denary) has ten as its base. It is the

4
24/10/202
numerical base most widely used by modern civilizations.
Binary Number System 6

4
24/10/202
 The binary numeral system (base two) has two as its base.
 It is the numerical base used by the modern day computers where numbers need to
be stored using the on/off logic of electronic and/or magnetic media. The ON and OFF
conveniently translate into 1 and 0.
Octal Number System 7

4
24/10/202
 The octal numeral system (base eight) has eight as its base.
Hexadecimal Number System 8

4
24/10/202
 The hexadecimal numeral system (base 16) has sixteen as its base.
 This system uses the 16 symbols: {0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F}
 The main advantage of using this numeral system is that it keeps the
representations short, and hence manageable.
 For example: the decimal number 199834, is represented in binary as
110000110010011010; and in hexadecimal as 30C9A.
Number Representations
 Dec (base 10) Bin (base 2) Oct (base 8) Hex (base
16) 0 0 0 0
1 1 1 1
2 10 2 2
3 11 3 3
4 100 4
0b
4
1111 1111 = 255
5 101 5 0b5 1 0000 0000 = 256
6 110 6 6
7 111 7 7 0o 77 = 63
8 1000 10 8
9 1001 11 9
0o 100 = 64
10 1010 12 a
11 1011 13 b 0x ff = 255
12 1100 14 c 0x 100 = 256
13 1101 15 d
14 1110 16 e
15 1111 17 f
16 1 0000 20 10
17 1 0001 21 11
18 1 0010 22 12
. . . .
. . . .

99
100
Why we need all these systems 10

4
24/10/202
 The length of representations can grow very rapidly in binary, and even decimal,
while slowly in hexadecimal, as extra symbols are allowed.
 So we need hexadecimal to keep things manageable on the paper.
 Computers need binary numbers, but humans can work better with decimal, octal
and hexadecimal.
 Hence we should know all these systems and how to convert numbers between these
different representations.
Digit & Position 11

4
24/10/202
 The length of a representation grows, from right to left, like: 0,1, 2, 3, … so on.
 Let’s take the example of the decimal system.
 The number nine, in decimal, consists of one digit ‘9’ at position 0.
 Similarly, all the numbers 0, 1, 2…,9 all consist of a single digit at position 0.
 But once we reach 9, we have run out of new symbols (in decimal system) and hence we
must increase the length.
 Therefore we add another digit to the left, at position 1. Hence we get 10,
11,12…,19,20,21,…,99.
 when again, we run out of all length-two combinations of symbols and must proceed to
length-three representations, starting from 100, so on.
Digit & Position 12

4
24/10/202
 In general, a number x may be represented with a representation of length n in the
following manner (here dp means the digit at position p).

dn-1 … d3 d2 d1 d0
 So for the number 199834, in decimal, d0=4, d1=3, d2=8, d3=9, d4=9 and d5=1.
 In general, We call the rightmost digit, d0, the least significant digit (LSB) and
the leftmost digit dn-1, the most significant digit (MSB).
BITS, BYTES and WORDS 13

4
24/10/202
 A digit in the binary system is more commonly called a bit.
 Therefore, a bit is a single digit in the binary representation of a number and is either
0 or 1.
 When a binary number is represented using 8 bits, the resulting representation,
composed of d0, d1, d2… d7, is called a byte.
 Similarly a binary representation composed of 16 bits is called a word, a binary
representation composed of 32 bits is called a double word, and a binary
representation composed of 64 bits is called a quadruple word.
BITS, BYTES and WORDS 14

4
24/10/202
 A less common, 4-bit representation of numbers is called nibble.
 The concept of a byte is fundamental in computer science because a byte is the
smallest addressable unit of memory in a modern computer; furthermore, data is
quantified in terms of byte!
 When you say that your hard-disk can store 20 Giga Bytes, you really mean that it
can store 20x230 bytes of data.
 A byte is therefore a unit for measuring data in computers.
BITS, BYTES and WORDS 15

4
24/10/202
 The following quantifiers are important:
 KILO
 1K = 210 So how many bytes in 37KB?
 MEGA
 1M = 220 So how many Kilo bytes in 137MB?
 GIGA
 1G = 230 So how many Tera bytes in 562MB?
 TERA
 1T = 240 So how Giga bytes in 307TB?
Representation of a Number 16

4
24/10/202
 What if I know the digits and want to get the actual representation for the number
from them?
 Assuming I cannot simply paste them together, but actually have to do a computation.
 I will do something like the following:
 199834 = 4x1+ 3x10 + 8x100 + 9x1000 + 9x10000 + 1x100000
 = 4x100+3x101+8x102+9x103+9x104+1x105
 In general, for the decimal system: D= ; where p represents the positions in an n-
digit number in the decimal system.
Method-I 17

4
24/10/202
 We can rewrite the above formula for any general (Base) radix r, which may be 10, 2,
8, 16 or anything we wish. Hence, we get:
 Let’s call this Method-I
 1011 = (1* 2^0)+(1*2^1)+(0*2^2)+(1*2^2)

 By this method we can compute any representation of any base (10, 2, 8, 16 ) and
find its equivalent value in base 10.
Converting numbers from other 18

bases to their decimal equivalents

4
24/10/202
 Binary 1001 (so r=2) :  Hexadecimal 12AC (so r=16):
 D = 1x20+0x21+0x22+1x23  D = Cx160+Ax161+2x162+1x163
= 1+0+0+8 = 12+160+512+4096
=9 = 4780
 Octal 1767 (so r=8) :
 (A represents a decimal 10 and C
 D = 7x80+6x81+7x82+1x83
represents a decimal 12)
= 7+48+448+512
= 1015
Converting Decimal Numbers into their 19
Equivalents in other Bases

4
24/10/202
 Generally, if we want to convert a decimal
number D into the equivalent number in
base r we will simply divide the number D by
the base r.
2|19 = 9 rem 1
 And then the successive quotients, by r, and 2|9 = 4 rem 1
pick the successive remainders as digits d0, d1 2|4 = 2 rem 0
and so on, of the equivalent number in base r. 2|2 = 1 rem 0

 We call this Method-II. d4 d3 d2 d1 d0


10011
Conversion from Base r to Base s 20

4
24/10/202
 Simply, we first convert the number into decimal using Method-
I, and then, from decimal to the desired base, using Method-II.
 So if you want to convert a number in base r to its equivalent
number in base s, you simply follow the following path:
Direct Conversions 21

4
24/10/202
 Sometimes it is much easier to convert numbers between bases directly (without
first converting them into decimal).
 You should know these methods for speeding up your calculations.

 http://www.mindspring.com/~jimvb/binary.htm
 http://atrevida.comprenica.com/atrtut01.html
22

4
24/10/202
We have seen positive numbers representation till now, how would
negative numbers will represent in binary system

direct Conversion from decimal to binary, is BCD


27 = 00100111
Negative Number 23

4
24/10/202
 How to represent negative number in binary system
 Signed Magnitude
 1’s Complement
 2’s Complement
Signed Magnitude 24

4
24/10/202
 Use the leftmost digit as a sign indication, and treat the remaining bits as if they
represented an unsigned integer.
 The convention is that if the leftmost digit (most significant bit) is 0 the number is
positive, if it’s 1 the number is negative.

 00001010 = decimal 10
 10001010 = decimal -10

 00000000
 10000000
Signed Magnitude 25

4
24/10/202
 The main problem with this system is that it doesn’t support binary arithmetic (which
is what the computer would naturally do).
 That is, if you add 10 and -10 binary you won’t get 0 as a result.
00001010 (decimal 10)
+ 10001010 (decimal -10)
_____________________
10010100 (decimal -20)
Sign/Magnitude Representation
 First Attempt: Sign/Magnitude Representation

 1 bit for sign (0=positive, 1=negative)


 N-1 bits for magnitude 0111 = 7
 Disadvantages:
lesser range
1111 = -7
unnatural results with arithemetic

 Problem? 0000 = +0
 Two zero’s: +0 different than -0
 Complicated circuits
1000 = -0

 Others attempts
1’s Complement 27

4
24/10/202
 To obtain one’s complement, you simply need to flip all the bits. (110) (001)
 Suppose we are working with unsigned integers.
 Decimal 10 is represented as: 00001010 128+64+32+16+8+4+2+1 =255
 It’s one complement would be: 11110101
 Notice that the complement is 245, which is 255 – 10.
 That is no co-incidence.
 The complement of a number is the largest number represented with the number of
bits available minus the number itself.
 Since we are using 8 bits here the maximum number represented is 255 (2^32 – 1). So the
complement of 10 will be 245.
9’s and 10’s complements 28

4
24/10/202
Understanding Computers: Today and Tomorrow
 1’s complement of 1 = 0
 Decimal 9’s complement 10’s complement
 921 078 79
 078
 689524 310475 310476
 34 65 66
 1011 0100 0101
 11011 00100 00101

 (r^n – 1) =
1’s Complement 29

4
24/10/202
 using the one’s complement system to represent negative numbers we would have
two zeroes: 00000000 (could be seen as +0) and 11111111 (could be seen as -0).
00001100 (decimal 12)
+11110011 (decimal -12)
____________________
11111111 (decimal -0)
1’s Complement 30

4
24/10/202
 this system partially solves the binary arithmetic problem
because there are some special cases left.
 00000011 (decimal 3)
 +11111101 (decimal -2) 00000010 11111101
 -------------
 100000000 (decimal 256)
 But since we have only 8 bits to represent the numbers, the
leftmost 1 will be discarded, and the result would be 00000000
(decimal +0).
 This is not the answer we expected.
2’s Complement 31

4
24/10/202
 Two’s Complement of a binary number is basically another
number which, when added to the original, will make all bits
become zeroes.
 You find a two’s complement by first finding the one’s
complement, and then by adding 1 to it.
 11110011 (one's complement of 12) 00001100
 +00000001 (decimal 1)
 -------------
 11110100 (two's complement of 12)
 +00001100
 0000000
Two’sWhat
Complement
 is used: Two’s Complement Representation
Representation

To negate any number:
 complement all the bits (i.e. flip all the bits)
 then add 1
 Nonnegative numbers are represented as usual
 0 = 0000, 1 = 0001, 3 = 0011, 7 = 0111
 To negate any number:
 complement all the bits (i.e. flip all the bits)
 then add 1
 -1: 1  0001  1110  1111
 -3: 3  0011  1100  1101
 -7: 7  0111  1000  1001
 -0: 0  0000  1111  0000 (this is good, -0 = +0)
Two’s Complement
Representation

One more example. How do we represent -
20?
20 = 0001 0100
20 = 1110 1011
+1
-20 = 1110 1100
2’s Complement 34

4
24/10/202
 Now let’s add 12 with -5 to see if we’ll have the same problem that we had when using the
one’s complement system:
 00001100 (decimal 12)
 +11111011 (decimal -5) 00000101 11111010 11111011
 -------------
 00000111 (decimal 7)

 (32) – (42)
 (100000) - (101010)
 010101 + 1 = 010110

 100000
 010110
 110110
 001001+1 = 001010= -10
35

24/10/202
4
Sources 36

4
24/10/202
 [1] http://en.wikipedia.org/wiki/Numeral_systems
 [2] http://www.mathsisfun.com/definitions/base-numbers-.html
 [3] http://atrevida.comprenica.com/atrtut01.html
 [4] http://www.mindspring.com/~jimvb/binary.htm

You might also like