Download presentation
Presentation is loading. Please wait.
Published byGabriella Mathews Modified over 9 years ago
1
CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett
2
Today’s Topics: 1. Number representations in different bases 2. Converting between bases 2
3
1. Number representations all your base are belong to us 3
4
Numbers are building blocks
5
Bases 5
6
Values in different bases What’s the decimal value of (10001) 2 ? A. (5) 10 B. (17) 10 C. (-1) 10 D. (10001) 10 E. None of the above / more than one of the above.
7
Values in different bases What’s the base 2 representation of the decimal number (42) 10 ? A. (111111) 2 B. (100001) 2 C. (101010) 2 D. (110011) 2 E. None of the above / more than one of the above.
8
Values in different bases What’s the biggest integer value whose binary representation has 4 bits? A. 2 4 = (16) 10 B. 2 3 = (8) 10 C. (4) 10 D. (1000) 10 E. None of the above / more than one of the above.
9
Uniqueness Is it possible to have two different representations for an integer in base 2? That is, is it possible to have A. No. B. Yes, but m has to be the same as n. C. Yes, and m,n can be different but for each kind of coefficient that appears in both, it has to agree. That is, a 0 = b 0, a 1 = b 1, etc. D. Yes, if m=n and all the coefficients agree. E. More than one of the above / none of the above.
10
Parity and shift
11
Shifts
12
Values in different bases What’s the base 2 representation of the decimal number (2014) 10 A. (11111011110) 2 B. (10000000000) 2 C. (10101010101) 2 D. (1000000001) 2 E. None of the above / more than one of the above.
13
Values in different bases What’s the base 2 representation of the decimal number (2014) 10 A. (11111011110) 2 B. (10000000000) 2 C. (10101010101) 2 D. (1000000001) 2 E. None of the above / more than one of the above. Is there a systematic way (aka algorithm) to do it?
14
Decimal to Binary conversion Right to left Questions to ask: Does it always terminate? Does it give the correct answer? What is the time complexity? toBinary(pos int n) Begin binary=“” i=n While i>0 Do If (i is even) Then binary=“0”+binary End If (i is odd) Then binary=“1”+binary End i=i DIV 2 Output binary End.
15
Other numbers? Fractional components Negative numbers aka how to subtract … first, how do we add? A. 111 B. 100 C. 1011 D. 1111 E. Other
16
One bit addition 1 0 1 + 1 1 0 1 0 0 1 1 Carry:
17
Subtraction JS p. 6 Borrowing A – B = (A – 10) + (10 – B) Carrying A – B = (A+10) – (B+10) Complementation A – B = A + B c = A + [ (99-B) - 99 ] = A + [ (100-B) – 100 ]
18
2’s complement 0000 0001 0010 1111 1110 1000 0111 0 1 2 -2 -7 -8 7 -3 1101 -4 1100 0011 3 1001 -5 -6 4 5 6 Complete the wheel of numbers! How many numbers are we representing with 4 bits?
19
How to add binary numbers? 1 1 0 0 1 0 1 0 1 +1 0 1 1 0 1 1 0 1 ? ? ? ? ?
20
How to add binary numbers? ? ? ? ? ? ? ? ? ? carry 1 1 0 0 1 0 1 0 1 +1 0 1 1 0 1 1 0 1 ? ? ? ? ?
21
How to add binary numbers? Two basic operations: One-Bit-Addition(bit1, bit2, carry) Next-carry(bit1, bit2, carry) ? ? ? ? ? ? ? ? ? carry 1 1 0 0 1 0 1 0 1 +1 0 1 1 0 1 1 0 1 ? ? ? ? ?
22
Numbers … logic … circuits
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.