Download presentation
Presentation is loading. Please wait.
Published byFlorence Stanley Modified over 9 years ago
1
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI N305 Information Representation: Negative Integer Representation
2
Dale Roberts Negative Numbers in Binary Four different representation schemes are used for negative numbers 1. Signed Magnitude Left most bit (LMB) is the sign bit : 0 positive (+) 1 negative (-) Remaining bits hold absolute magnitude Example: 2 10 0000 0010 b -2 10 1000 0010 b Q: 0000 0000 = ? 1000 0000 = ? Try, 1000 0100 b =-4 10
3
Dale Roberts 1’s Complement 2.One’s Complement – –Left most bit is the sign bit : 0 positive (+) 1 negative (-) – –The magnitude is Complemented Example: 2 10 0 000 0010 b -2 10 1 111 1101 b Exercise: try - 4 10 using 1’s Complement Q: 0000 0000 = ? 1111 1111 = ? 1111 1111 = ? Solution: 4 10 = 0 000 0100 b -4 10 = 111 1011 b 1
4
Dale Roberts 2’s Complement 3.2’s Complement Sign bit same as above Magnitude is Complemented first and a “1” is added to the Complemented digits Example: 2 10 0 000 0010 b 1’s Complement 1 111 1101 b + 1 -2 10 1 111 1110 b 7 10 1’s Complement + 1 -7 10 Exercise: try -7 10 using 2’s Complement 0000 0111 b 1111 1000 b 1111 1001 b
5
Dale Roberts 2’s Complement 7 10 = 0000 0111 b 3 10 = 0000 0011 b 1’s complement 1111 1100 b 2’s complement 1111 1101 b -3 10 7+(-3) 0000 0111 +1111 1101 +1111 1101 Example: 7+(-3) [hint]: A – B = A + (~B) +1 1 1111 111 carry ignore 1 0000 0100 0000 0100 4 10
6
Dale Roberts Three Representation of Signed Integer
7
Dale Roberts Negative Numbers in Binary (cont.) 4. Excess Representation – – For a given fixed number of bits the range is remapped such that roughly half the numbers are negative and half are positive. Example: (as left) Excess – 8 notation for 4 bit numbers Binary value = 8 + excess-8 value MSB can be used as a sign bit, but If MSB =1, positive number If MSB =0, negative number Excess Representation is also called bias Numbers Binary Value Notation Excess – 8 Value 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 -8 -7 -6 -5 -4 -3 -2 0 1 2 3 4 5 6 7
8
Dale Roberts Fundamental Data Types 2 byte unsigned (Default type is int ) 2 byte int 0000 0000 0000 0000 ( 0 D ) 0000 0000 0000 0001 ( 1 D ) 0000 0000 0000 0010 ( 2 D ) …. 0111 1111 1111 1111 ( 32767 D 2 15 -1) 1000 0000 0000 0000 ( 32768 D 2 15 ) …. 1111 1111 1111 1111 ( 2 16 –1) 1000 0000 0000 0000 ( -32768 D - 2 15 ) 1000 0000 0000 0001 ( -32767 D - 2 15 +1) …. 1111 1111 1111 1110 ( - 2 D ) 1111 1111 1111 1111 ( - 1 D ) 0000 0000 0000 0000 ( 0 D ) 0000 0000 0000 0001 ( 1 D ) 0000 0000 0000 0010 ( 2 D ) …. 0111 1111 1111 1111 ( 32767 D 2 15 -1) With vs. without using sign bit With vs. without using sign bit For a 16 bit binary pattern:
9
Dale Roberts Fundamental Data Types Four Data Types in C Four Data Types in C (assume 2’s complement, byte machine) Data Type Abbreviation Size (byte) Range char 1-128 ~ 127 unsigned char10 ~ 255 int 2 or 4-2 15 ~ 2 15 -1 or -2 31 ~ 2 31 -1 unsigned int unsigned 2 or 40 ~ 65535 or 0 ~ 2 32 -1 short int short 2-32768 ~ 32767 unsigned short int unsigned short 20 ~ 65535 long int long 4-2 31 ~ 2 31 -1 unsigned long int unsigned long 40 ~ 2 32 -1 float4 double8 Note:2 7 = 128, 2 15 =32768, 2 15 = 2147483648 Complex and double complex are not available
10
Dale Roberts Acknowledgements These slides where originally prepared by Dr. Jeffrey Huang, updated by Dale Roberts.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.