DIGITAL SYSTEMS Number systems & Arithmetic Rudolf Tracht and A.J. Han Vinck
Number Systems A set of symbols representing digits, S A string of symbols represents a value Value may be computed from the position of digits in a string (positional number system) Example: Decimal number system –base 10 or radix 10 –(724.6) 10 =7x x10 + 4x1 + 6x1/10
examples Decimal: r = 10, S = {0, 1, 2,..., 9} Binary: r = 2, S = {0,1} Octal: r = 8, S = {0,1,2,3,4,5,6,7} Hexadec: r = 16, S = {0,..., 9, A,B,C,D,E,F} Conversion from one base to another: -By successive division or multiplications by the radix.
Positional number system Base r A number is a string Significance of a digit in a string is indicated by its position
Example for binary numbers A binary number is a weighted number. The structure is 2 n-1 2 -n where n is the number of bits from the binary point. Ex: conversion of the binary number –Weight –Binary = = =
2-to-10 and 10-to-2 Converting a binary number to a decimal number is easy : there is a radix point here What about the way back?
Addition and subtraction of binary numbers Same as in school: borrow from preceding neighbor By example:
Multiplication/division Examples –Multiplication: 7 x 5 = x 101 = = = 35 –Division: 12 / 4 = / 100 = 11
Negative numbers Signed magnitude form 1- complement 2-complement
Signed magnitude representation The most significant bit indicates the sign – = +85 – = - 85 Problem is the adding/subtracting of numbers
1-complement representation Binary complement for negative numbers 17 = = = = -119 sign
2-complement representation Positive numbers +A Negative numbers -A where
4-bit numbers
remarks Adding/subtracting – ignoring any carries beyond the MSB MSB = most significant bit (largest weight) – correct as long as range not exceeded
implementation Note: we represent a negative number –A as Example: 99 = = = Example: 98 = = =
Overflow detection MSB different No problem –Reason: always within range Example: MSB the sameMSB addition different Example: = =-5
In other words Calculations are done modulo 2 r+1 Let a and b be positive numbers; 0 a,b < 2 r ; - a = 2 r+1 – a mod 2 r+1 + a + b + a + b = c < 2 r no problem ( overflow detected by sign comparison) - a - b - a - b = 2 r+1 – a + 2 r+1 – b = 2 r+1 – (a + b) + 2 r+1 = 2 r+1 – (a + b) modulo 2 r+1 no problem if (a + b) < 2 r ( otherwise overflow detected ) - a + b - a + b = 2 r+1 – a + b = b –a modulo 2 r+1 for b a = 2 r+1 – (a - b ) for b a
Floating point numbers Decimal –Example: x 10 9 sign mantissa exponent
Binary floating point (IEEE standard) Binary: –single- (32 bits), double- (64 bits), extended precision (80 bits) S E = exponent F = mantissa 1 8 bits 23 bits To find E and F, write a binary number as 1. a 1 a 2 a 3 a 4 … 2 x –F = a 1 a 2 a 3 a 4 … –E = x range of x: -126 ≤ x ≤ 128 The number 0.0 is represented by all 0’s Infinity is represented by all 1’s in the exponent and 0’s in the mantissa Number = (-1) S (1+F)(2 E-127 )
Hexadecimal numbers Widely used in computer and microprocessor applications Base is 16: Decimalbinary hexadecimal – – – – – – – – – – –101010A –111011B –121100C –131101D –141110E –151111F
Hexadecimal numbers (count) A B C D E F A 1B 1C 1D 1E 1F A 2B 2C 2D 2E 2F 30 etc. i.e. In decimal13 16 means 1 x C 16 means 2 x A2B 16 means 10 x x With 2 hexadecimal digits we can count up to FF 16 = 255 decimal Each hexadecimal character represents a 4-bit number!
Hexadecimal numbers (examples) Example Binary to hexadecimal C A F Example Hexadecimal to binary 6BD3 = 6 x x x in binary:
octal numbers used in computer and microprocessor applications Base is 8: Decimalbinary octal – – – – – – – – – – – – – – – –
octal numbers (count) etc. i.e. In decimal13 8 means 1 x means 2 x means 3 x x With 2 octal digits we can count up to 77 8 = 63 decimal Each octal character represents a 4-bit number!
octal numbers (examples) Example Binary to octal Example octal to binary 6233 = 6 x x x in binary:
octal numbers (examples) Conversion digital to octal Example: 359 decimal = 5 x 8 2 (320) + 4 x 8 (32) + 7
Binary Coded Decimal Conversion table DecimalBCD decimal 35 = BCD 30011decimal 98 = BCD BCD = 86 decimal
Some other codes DecimalBCD 1-out-of-10 Biquinary Binary coded decimal Application: error detection (check!)
Gray Code By example for binary words of length 3 # codeword numbers differ by 1 binary difference Homework: design a general code for length n
parity An extra bit is added to a string to make the number of 1’s always even (or odd if desired) –i.e. the parity for 011 is the parity for 111 is RESULT: any odd number of changes detectable!