# 8 October 2013Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems.

## Presentation on theme: "8 October 2013Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems."— Presentation transcript:

8 October 2013Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems sjmaybank@dcs.bbk.ac.uk Autumn 2013 Week 2b: Decimal and Binary Number Representations

Decimal Representation of Integers An integer is any whole number, positive or negative, eg …, -2, -1, 0, 1, 2, 3,… In the decimal representation an integer is written as a sum of powers of 10, eg 8 October 2013Brookshear, Section 1.52

Places and Powers of 10 The decimal digits are 0,1,3,4,5,6,7,8,9. Let s be a string of k decimal digits, 8 October 2013Brookshear, Section 1.53 The digit in the ith place is d i The power of 10 associated with the digit in the ith place is 10 i-1 10 0 =1

Decimal Addition 8 October 2013Birkbeck College, U. London4 Note the carry from the left most column to the next column to the right

Decimal Addition in Terms of Powers of 10 8 October 2013Birkbeck College, U. London5

Curious Properties of the Decimal Representation A number is divisible by 3 if and only if the sum of its decimal digits is divisible by 3. A number is divisible by 11 if and only if the sum of its decimal digits in the even places minus the sum of its decimal digits in the odd places is divisible by 11. 8 October 2013Birkbeck College, U. London6

8 October 2013Birkbeck College, U. London7 Bits and Bytes A bit (binary digit) takes the value 0 or 1. A bit string is a list of bits in a fixed order. A byte is a bit string of length 8. Leftmost bit: most significant bit Rightmost bit: least significant bit Megabyte: 10 6 bytes (or sometimes 2 20 bytes).

8 October 2013Birkbeck College, U. London8 Computer Data Number: bit string Persons name: bit string Memory address: bit string Current time: bit string All data inside a computer are recorded as bit strings Corollary: a bit string on its own can mean anything

8 October 2013Brookshear, Section 1.59 Binary Representation of Integers 1011 representation onetwoeightfour Binary (base two) system The binary digits are 0, 1 An integer is represented as a sum of powers of 2

8 October 2013Birkbeck College, U. London10 Notation BinaryInteger[11101]=DecimalInteger[29]. BinaryInteger[1100101]=DecimalInteger[101].

8 October 2013Birkbeck College, U. London11 Some Integers Binary IntegerDecimal Integer 00 11 102 113 1004 1015 1106 Power of 2: BinaryInteger[10…0]

8 October 2013Brookshear, Section 1.512 Conversion from Binary to Decimal BinaryInteger[b(n)….b(1)]= DecimalInteger[b(n)2 n-1 +b(n-1)2 n-2 +…+b(1)] Example: BinaryInteger[1101]= DecimalInteger[1x2 3 +1x2 2 +0x2 1 +1] = DecimalInteger[8+4+1]= DecimalInteger[13]

8 October 2013Brookshear, Section 1.513 Addition of Binary Bits 1+1 = 0 carry 1 1+0 = 1 0+1 = 1 0+0 = 0

8 October 2013Birkbeck College, U. London14 Example of Binary Addition (2 3 +2 1 +1)+(2 1 +1) = 2 3 +(1+1)x2 1 +1+1 = 2 3 +(1+1)x2 1 +2 1 = 2 3 +(1+1+1)x2 1 = 2 3 +(2+1)x2 1 = 2 3 +2 2 +2 1 1011 +11 ==== 1110

8 October 2013Birkbeck College, U. London15 Examples Convert DecimalInteger[13] to a binary integer. Convert BinaryInteger[10010] to a decimal integer. Add BinaryInteger[1101] to BinaryInteger[110]

8 October 2013Birkbeck College, U. London16 Multiplication of Binary Numbers Multiply by a power of 2: add zeros on the right, e.g. 1011 x 100 = 101100 110 x 10 = 1100 In general, reduce to multiplication by a sum of powers of 2, e.g. 1011x11 = 1011x(10+1) = 1011x10+1011x1 = 10110+1011 = 100001

8 October 2013Brookshear, Section 1.517 Conversion to Binary Input: non-negative integer m Output: bit string b such that m= BinaryInteger[b] 1.If[m==0, Output {0}; Halt]; 2.b = {}; /* empty bit string */ 3.While(m>0) 4. Divide m by 2, to give quotient q, remainder r; 5. m = q; 6. b = Prepend[r,b]; 7.EndWhile 8.Output b; 9.Halt;

8 October 2013Brookshear, Section 1.518 Conversion from Binary to Decimal Input: non-empty bit string b Output: decimal integer m such that m = BinaryInteger[b] 1.m = 0; 2.While (b is not empty) 3. r = left most bit of b; 4. m = m+r 2 Length[b]-1 ; 5. b = b with left most bit deleted; 6.EndWhile; 7.Output m; 8.Halt;

8 October 2013Brookshear, Section 1.119 Hexadecimal Representation 0000=0, 0001=1, 0010=2, 0011=3, 0100=4, 0101=5, 0110=6, 0111=7, 1000=8, 1001=9, 1010=A, 1011=B, 1100=C, 1101=D, 1110=E, 1111=F Example BinaryInteger[10101011011010110100] = 10101011011010110100 = HexadecimalInteger[AB6B4] BinaryInteger[]

Download ppt "8 October 2013Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems."

Similar presentations