• No results found

Number System

N/A
N/A
Protected

Academic year: 2020

Share "Number System"

Copied!
39
0
0

Loading.... (view fulltext now)

Full text

(1)

Number System

(Different Ways To Say How Many)

Spring 2017

INTRODUCTION TO INFORMATION AND COMMUNICATION TECHNOLOGIES EMAIL: [email protected]

WEBSITE:

(2)

Outline

► Numeral System ► Decimal System ► Binary System ► Octal System ► Hexadecimal System

► Digit and Positions

► Bits, Bytes & Words

► Conversions

► Negative Numbers

2/4/2017 Mehwish Fatima- CIIT Lahore

(3)

Numeral System

► 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.

2/4/2017

(4)

Base/Radix of Numeral System

► 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.

2/4/2017

4

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.

(5)

Decimal Number System

► The decimal numeral system (base ten or denary) has ten as its base. It is the numerical base most widely used by modern civilizations.

2/4/2017

(6)

Binary Number System

► 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.

2/4/2017

(7)

Octal Number System

► The octal numeral system (base eight) has eight as its base.

2/4/2017

(8)

Hexadecimal Number System

► 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.

2/4/2017

(9)

Why we need all these systems

► 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.

2/4/2017

(10)

Digit & Position

► 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.

2/4/2017

(11)

Digit & Position

► 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).

► 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, d

0, the least significant digit (LSB) and the leftmost digit dn-1,

the most significant digit (MSB).

2/4/2017

(12)

BITS, BYTES and WORDS

► 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.

2/4/2017

(13)

BITS, BYTES and WORDS

► 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.

2/4/2017

(14)

BITS, BYTES and WORDS

► 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?

2/4/2017

(15)

Representation of a Number

2/4/2017

(16)

Hold on! Can we use this method to convert a

number from any other base to decimal?

2/4/2017

16

(17)

Method-I

2/4/2017

(18)

Converting numbers from other bases to

their decimal equivalents

► Binary 1001 (so r=2) : ► D = 1x20+0x21+0x22+1x23 = 1+0+0+8 = 9 ► Octal 1767 (so r=8) : ► D = 7x80+6x81+7x82+1x83 = 7+48+448+512 = 1015

► Hexadecimal 12AC (so r=16):

► D = Cx160+Ax161+2x162+1x163 = 12+160+512+4096

= 4780

► (A represents a decimal 10 and C represents a decimal 12)

2/4/2017

(19)

This is cool! But how do we solve the converse

problem? How do we convert decimal numbers

into binary, octal and hexadecimal?

2/4/2017 Mehwish Fatima- CIIT Lahore

(20)

Decimal to Binary Conversion

2/4/2017

(21)

Decimal to Binary Conversion

► Now let me repeat this process on the number q

► Can you see what is happening?

► Continuing this process we will reach a point where the quotient cannot be further divided.

2/4/2017

(22)

Decimal to Binary Conversion

► And at this point we will have derived the following formula:

► Which is exactly the same as Method-I !!!

► So it turns out that by dividing we were only doing the opposite operation of what we had done before.

► Hence our assumption of taking the successive remainders as d0, d1 and so on was in fact correct!

2/4/2017

(23)

Converting Decimal Numbers into their Equivalents in

other Bases

► 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.

► And then the successive quotients, by r, and pick the successive remainders as digits d0, d1 and so on, of the equivalent number in base r.

We call this Method-II.

2/4/2017

(24)

Conversion from Base r to Base s

► Now we posses enough knowledge to covert a number from any given base to a desired base.

► 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:

2/4/2017

(25)

Direct Conversions

► 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.

► Here are some sources for learning these:

► http://www.mindspring.com/~jimvb/binary.htm

► http://atrevida.comprenica.com/atrtut01.html

2/4/2017

(26)

We have seen positive numbers representation till now, how would negative numbers will represent in binary system

2/4/2017

(27)

Negative Number

► How to represent negative number in binary system

► Signed Magnitude

► 1’s Complement

► 2’s Complement

2/4/2017

(28)

Signed Magnitude

► 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

2/4/2017

(29)

Signed Magnitude

► 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) 2/4/2017

29

(30)

1’s Complement

► To obtain one’s complement, you simply need to flip all the bits.

► Suppose we are working with unsigned integers.

► Decimal 10 is represented as: 00001010

► 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.

2/4/2017

(31)

1’s Complement

► 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) 2/4/2017

31

(32)

1’s Complement

► this system partially solves the binary arithmetic problem because there are some special cases left.

► 00000011 (decimal 3)

► +11111101 (decimal -2)

---► 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/4/2017

(33)

2’s Complement

► 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) ► +00000001 (decimal 1) ► --- ► 11110100 (two's complement of 12) 2/4/2017

33

(34)

2’s Complement

► 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) ► ---► 00000111 (decimal 7) 2/4/2017

34

(35)

2/4/2017

(36)

Number Overflow

► Overflow occurs when the value that we compute cannot fit into the number of bits we have allocated for the result.

► For example, if each value is stored using eight bits, adding 127 to 3 would overflow: ► 01111111 ► + 00000011 ► ---► 10000010 2/4/2017

36

(37)

Number Overflow

► 100000010 in our scheme represents 126, not +130. If, however, we were not representing negative numbers, the result would be correct.

2/4/2017

(38)

Code for Letters and Symbols

► Computers use a standard binary code to represents letters of the alphabet, numerals, punctuation marks and other special characters.

► The code is called ASCII (pronounced “askey”) which stands for “American Standard Code for Information Interchange.”

► There are 256 code combinations.

2/4/2017

(39)

Sources

► [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 2/4/2017

39

References

Related documents

When converting a number of base 8 to a number of base 10, we apply the same logic as with the previous binary and decimal numbers.. The first six letters of the alphabet

The main difference would be that the Babylonians used two triangular or wedge-shaped symbols to create 59 base units where as we have 10 different symbols for base numeric

Segmentation procedure stack main() symbols sys library stack sys library procedure symbols main() Limit Base 0 1 2 3 4 0 1 2 3 4 1000 200 5000 200 300 0 200 5200 5300 5600 5700

†Symbols in parentheses represent chord names with respect to GCFBbDG tuning (or Capoed Gtr, TAB 0 = 3rd fret) Symbols above represent actual sounding chords.. Play Guitar 1

Note: The two symbols associated with trademarks ™ (the trademark symbol) and ® (the registered trademark symbol) represent the status of a mark and accordingly its level of

The concepts and the algorithm developed will be illustrated by a numerical example for which n=5; p=3; q=2; F 0 =2 and C 0 =3. In this numerical example given 5 jobs can assign on

This is known as fixed-point representation where the position of decimal point is fixed and number of bits before and after decimal point are also predefined..

Rounding Decimal Numbers Nearest Whole Number is a KS2 Year 5 9-10 yrs old worksheet helping teach Number Place Value and Fractions in Maths.. Anytime we want something that any