Number Systems: Negative Integers and Floating Point - PowerPoint PPT Presentation

1 / 10
About This Presentation
Title:

Number Systems: Negative Integers and Floating Point

Description:

Department of Computer and Information Science, School of Science, IUPUI CSCI 230 Information Representation: Negative Integer Representation Dale Roberts, Lecturer – PowerPoint PPT presentation

Number of Views:108
Avg rating:3.0/5.0
Slides: 11
Provided by: DaleRo6
Learn more at: http://cs.iupui.edu
Category:

less

Transcript and Presenter's Notes

Title: Number Systems: Negative Integers and Floating Point


1
Department of Computer and Information
Science,School of Science, IUPUI
CSCI 230
Information Representation
Negative Integer Representation
Dale Roberts, Lecturer IUPUI droberts_at_cs.iupui.edu
2
Negative Numbers in Binary
  • Four different representation schemes are used
    for negative numbers
  • Signed Magnitude
  • Left most bit (LMB) is the sign bit
  • 0 ? positive ()
  • 1 ? negative (-)
  • Remaining bits hold absolute magnitude
  • Example
  • 210 ? 0000 0010b
  • -210 ? 1000 0010b
  • Q 0000 0000 ?
  • 1000 0000 ?

Try, 1000 0100b
-410
3
1s Complement
  • Ones Complement
  • Left most bit is the sign bit
  • 0 ? positive ()
  • 1 ? negative (-)
  • The magnitude is Complemented
  • Example
  • 210 ? 0 000 0010b
  • -210 ? 1 111 1101b
  • Exercise try - 410 using 1s Complement
  • Q 0000 0000 ?
  • 1111 1111 ?

Solution 410 0 000 0100 b -410
111 1011 b
1
4
2s Complement
  • 2s Complement
  • Sign bit same as above
  • Magnitude is Complemented first and a 1 is
    added to the Complemented digits
  • Example
  • 210 ? 0 000 0010b
  • 1s Complement ? 1 111 1101b
  • 1
  • -210 ? 1 111 1110b

Exercise try -710 using 2s Complement
710 ? 1s Complement ? 1
-710 ?
0000 0111b
1111 1000b
1111 1001b
5
2s Complement
Example 7(-3) hint A B A (B) 1
  • 710 0000 0111b
  • 310 0000 0011b
  • 1s complement 1111 1100b
  • 2s complement 1111 1101b ? -310
  • 7(-3) ? 0000 0111
  • 1111 1101

1 1111 111 carry
ignore 1 0000 0100 ? 0000 0100 ? 410
6
Three Representation of Signed Integer
7
Negative Numbers in Binary (cont.)
  • 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 -1 0 1 2 3 4 5 6 7
8
Fundamental Data Types
  • With vs. without using sign bit
  • For a 16 bit binary pattern

2 byte unsigned (Default type is int) 2 byte int
0000 0000 0000 0000 ( ? 0D) 0000 0000 0000 0001 ( ? 1D ) 0000 0000 0000 0010 ( ? 2D ) . 0111 1111 1111 1111 ( ? 32767D ? 215 -1) 1000 0000 0000 0000 ( ? 32768D ? 215) . 1111 1111 1111 1111 (? 216 1) 1000 0000 0000 0000 ( ? -32768D ? - 215 ) 1000 0000 0000 0001 ( ? -32767D ? - 215 1) . 1111 1111 1111 1110 ( ? - 2D ) 1111 1111 1111 1111 ( ? - 1D ) 0000 0000 0000 0000 ( ? 0D ) 0000 0000 0000 0001 ( ? 1D ) 0000 0000 0000 0010 ( ? 2D ) . 0111 1111 1111 1111 ( ? 32767D ? 215 -1)
9
Fundamental Data Types
  • Four Data Types in C (assume 2s complement, byte
    machine)

Data Type Data Type Abbreviation Size (byte) Range
char char 1 -128 127
char unsigned char 1 0 255
int int 2 or 4 -215 215-1 or -231 231-1
int unsigned int unsigned 2 or 4 0 65535 or 0 232-1
int short int short 2 -32768 32767
int unsigned short int unsigned short 2 0 65535
int long int long 4 -231 231-1
int unsigned long int unsigned long 4 0 232-1
float float 4
double double 8
Note 27 128, 215 32768, 215
2147483648 Complex and double complex are not
available
10
Acknowledgements
  • These slides where originally prepared by Dr.
    Jeffrey Huang, updated by Dale Roberts.
Write a Comment
User Comments (0)
About PowerShow.com