Presentation is loading. Please wait.

Presentation is loading. Please wait.

Prof. Giancarlo Succi, Ph.D., P.Eng.

Similar presentations


Presentation on theme: "Prof. Giancarlo Succi, Ph.D., P.Eng."— Presentation transcript:

1 Prof. Giancarlo Succi, Ph.D., P.Eng. E-mail: Giancarlo.Succi@unibz.it
Binary Numbers Prof. Giancarlo Succi, Ph.D., P.Eng. Prof. G. Succi, Ph.D., P.Eng.

2 Content Number and numerals Numeric systems Base conversion
Finite precision numbers Binary arithmetic Floating point representations Prof. G. Succi, Ph.D., P.Eng.

3 Numbers And Numerals Number: abstract entity
Numeral: string of symbols that represent a number in a given system The same number can be represented by different numerals in different numeric systems Example 234 in decimal system CCXXXIV using roman system Discuss the role of roman numbers Present the concept of base as “up-to” Start doing the base 2 as 0, 1, 10, 11, 100, 101, … Then show the base 3, 4 etc. Explain why the base 2 is so important The same numeral stands for different numbers if different systems are used Example (10)10=10 (10)2 = ( 2 )10= 2 Prof. G. Succi, Ph.D., P.Eng.

4 Numeric Systems (1) To define a Numeric System we need:
a set of symbols that we will call digits (E.g. 1,2,3, X,K, ….) some rules to build up numbers We can define Positional Numeric System or Non Positional Numeric Systems Non Positional Numeric System: the value of digits in the number is position independent Example In Roman Numeric System: the symbol V means 5 always, but IV  VI …. Prof. G. Succi, Ph.D., P.Eng.

5 Numeric Systems (2) Positional Numeric System: digit value depends on its position within the number (weight) Each digit represents the coefficient of a power of the base Exponent is given by the position of the digit within the number position m-1 position -1 position -k position m position 0 comma position -2 Prof. G. Succi, Ph.D., P.Eng.

6 Numeric Systems (3) The Decimal System 125.42
Positional Numeric System: digit value depends on its position within the number (weight) Example The Decimal System 125.42 Prof. G. Succi, Ph.D., P.Eng.

7 Numeric Systems (4) The Binary System 101.01 Example
Prof. G. Succi, Ph.D., P.Eng.

8 Numeric Systems (5) Other Systems Used Octal System: Example base = 8
symbols used = 0,1,2,3,4,5,6,7 Hexadecimal System: base = 16 symbols used = 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F Prof. G. Succi, Ph.D., P.Eng.

9 Base Conversion (decimal to binary)
Is obtained by repeatedly dividing the number by 2, the remainder of division at each step is the digit of the binary number (starting from less significant digits) ( ) 2 10 11010 26 digit t significan more 1 / 3 6 13 less = ï þ ý ü rem The first method is the one used Ask a few students to do it Tell to remember to do it the other way around … or by determining the powers of 2 contained in the number: Prof. G. Succi, Ph.D., P.Eng.

10 Base Conversion (binary to decimal )
Is obtained by strictly applying the definition: How do we convert binary to hexadecimal? Show the long process and then the shortcut for it. Same for octal. Prof. G. Succi, Ph.D., P.Eng.

11 Finite precision numbers (1)
Finite Precision numbers: numbers with a finite number of digits. Some properties are lost: operators closure distributive, associative properties holes in the representation of real numbers Example Lets use numbers with 2 decimal numbers with sign Interval represented: [+99, -99] Closure respect operator + is lost: = ??? (106 is out of the interval) Associative property: 25+ (90-30)  (25+ 90)-30 Prof. G. Succi, Ph.D., P.Eng.

12 Finite precision numbers (2)
Example Lets use consider numbers with just two two decimal digit: Interval represented: [+0.99, -0.99] We cannot represent a number between 0.05 and 0.06 Prof. G. Succi, Ph.D., P.Eng.

13 Represented Intervals
By representing positive integers in binary notation, n digits (bits), cover the interval [0,2n-1] It is easy to note that if the maximum number representable using n bit is X = 2n -1 then to represent number X are necessary n = Int( log2 (X)+1) bits Example using n=3 interval [0, 7] is completely represented Int is the next integer Prof. G. Succi, Ph.D., P.Eng.

14 Positive and negative integers in base 2 (1)
To represent Integer Relative Numbers, if the same number of digits is used, the interval of absolute is halved Several notations are used: Signed Magnitude the first bit is used for the sign 0 : + ; 1 : - n-1 bits are used for the magnitude represented interval: [-2n-1 +1, 2n-1 -1] Note that 0 has two possible representations Example using n=4 interval [-7, 7] is completely represented Representations: 1000 and 0000 Prof. G. Succi, Ph.D., P.Eng.

15 Positive and negative integers in base 2 (2)
One’s Complement a 0 is added on left of positive numbers to change sign the numeral is complemented bit by bit positive numerals start with 0, negative ones with 1 n-1 bits are used for the magnitude represented interval: [-2n-1 +1, 2n-1 -1] Note that 0 has two representations Example using n=4 interval [-7, 7] is completely represented ( -7+2) Representations for 0: 1000 and 0000 Prof. G. Succi, Ph.D., P.Eng.

16 Positive and negative integers in base 2 (3)
Two’s Complement a 0 is added on left of positive numbers negative numbers are obtained by complementing bit by bit the corresponding positive a and then adding 1 positive numerals start with 0, negative ones with 1 n-1 bits are used for the magnitude represented interval: [-2n-1, 2n-1 -1] We earned a number by giving 0 just one representation Example using n=4 interval [-8, 7] is completely represented Prof. G. Succi, Ph.D., P.Eng.

17 Positive and negative integers in base 2 (4)
Excess Notation numbers are represented as a sum of the number with a power of 2 Using n bits excess 2n-1 is used represented interval: [-2n-1, 2n-1 -1] practical rule: numerals are obtained by complementing the highest digit in 2’s complement notation Example using n=4 interval [-8, 7] excess=8 =  =  Prof. G. Succi, Ph.D., P.Eng.

18 Binary Arithmetic (1) the sum
Sum in binary notation is performed bit by bit carrying the rest to next digit Example Prof. G. Succi, Ph.D., P.Eng.

19 Binary Arithmetic (2) the sum in 2’s C
In 2’sC sum and subtraction are managed in the same way, just throw away Carry Carry is thrown away If the two terms have different sign the result is always correct. If the two terms have the same sign but the result has a different one …. … we have an ERROR Example What about the sum using 8 bit representation in 2’sC Overflow Error ! Prof. G. Succi, Ph.D., P.Eng.

20 Binary Arithmetic (3) multiplication
Easy ... repeated addition ….. or the usual rules learned for the product of integers or real numbers can be used, recalling the following multiplication table: 0 1 Prof. G. Succi, Ph.D., P.Eng.

21 Floating Point Notation
Example Using Base 10 Using numerals with 5 digits of the kind  .XXX  EE Mantissa =  .XXX three signed digits 0.1 | m |  1 Exponent =  EE two signed digits  e  99 Represented numbers are: Represented interval is Negative Overflow Positive Overflow Positive Underflow Negative Underflow Prof. G. Succi, Ph.D., P.Eng.

22 Standard IEEE 754 (1985) Standard definition (i.e. architecture independent) Simple precision ( uses 32 bits to represent sign, exponent and mantissa Double precision (uses 64 bits) There are notation using normalized mantissa or not Some configurations of the exponent are reserved (i.e. not standardized) +/- (1 bit) Exponent (8 bit) Mantissa (23 bit) +/- (1 bit) Exponent (11 bit) Mantissa (52 bit) Prof. G. Succi, Ph.D., P.Eng.

23 Floating Point Sum To sum (or subtract) floating point numbers it is necessary to scale mantissa to have the same exponents in all terms Example n1 + n2 : using standard IEEE 754 notation in 32 bits Note that lower terms is loosing digits Prof. G. Succi, Ph.D., P.Eng.

24 Floating Point product
Multiply mantissa and sum exponents If necessary mantissa is scaled and exponent is incremented/decremented Example n1 x n2 : using standard IEEE 754 notation in 32 bits Prof. G. Succi, Ph.D., P.Eng.

25 Binary Arithmetic (4) division
For your knowledge Binary Arithmetic (4) division Need to represent fractions Prof. G. Succi, Ph.D., P.Eng.

26 Fractional Representation
For your knowledge Fractional Representation Fixed Point Notation: stores numerals as: Floating Point Notation: A n digit floating point number in base b is represented by. Where is a numeral in base b called mantissa normalized with and e is an integer called the exponent. Prof. G. Succi, Ph.D., P.Eng.


Download ppt "Prof. Giancarlo Succi, Ph.D., P.Eng."

Similar presentations


Ads by Google