Number Systems: Negative Integers and Floating Point

Number Systems: Negative Integers and Floating Point

Department of Computer and Information Science, School of Science, IUPUI CSCI N305 Information Representation: Negative Integer Representation 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: 210 0000 0010b Try, 1000 0100b = -410 -210 1000 0010b Q: 0000 0000 = ? 1000 0000 = ? Dale Roberts 1s Complement 2. 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 -410 = 1 111 1011 b b Dale Roberts 2s Complement 3. 2s Complement Sign bit same as above Magnitude is Complemented first and a 1 is added to the Complemented digits Example: 210 0 1s Complement 1 + -210 1 000 0010b 111 1101b 1 111 1110b Exercise: try -710 using 2s Complement 710 0000 0111 b 1s Complement 1111 1000b + 1 -710 1111 1001b Dale Roberts 2s Complement Example: 7+(-3) [hint]: A B = A + (~B) +1 710 = 0000 0111b 310 = 0000 0011b

1s complement 1111 1100 b 2s complement 1111 1101 -310 b 1 1111 111 carry 7+(-3) 0000 0111 + 1111 1101 ignore 1 0000 0100 0000 0100 410 Dale Roberts Three Representation of Signed Integer Representation 0 0000 0 0001 0 0010 0 0011 0 0100 0 0101 0 0110 0 0111 0 1000 0 1001 0 1010 0 1011 0 1100 0 1101 0 1110 0 1111 1 0000 1 0001 1 0010 1 0011 1 0100 1 0101 1 0110 1 0111 1 1000 1 1001 1 1010 1 1011 1 1100 1 1101

1 1110 1 1111 Value Representation Signed Magnitude 1's Complement 2's Complement 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 -0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 0 1 2 3 4 5

6 7 8 9 10 11 12 13 14 15 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 -0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 -16 -15

-14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 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 0 1 2 3 4 5 6 7

8 9 10 11 12 13 14 15 Notation Excess 8 Value 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 Dale Roberts Fundamental Data Types With vs. without using sign bit For a 16 bit binary pattern: 2 byte unsigned (Default type is 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) 2 byte int 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) Dale Roberts Fundamental Data Types Four Data Types in C (assume 2s complement, byte machine) Data Type char Abbreviation Size (byte) Range

char 1 -128 ~ 127 unsigned char 1 0 ~ 255 2 or 4 -215 ~ 215-1 or -231 ~ 231-1 2 or 4 0 ~ 65535 or 0 ~ 232-1 int int unsigned int unsigned short int short 2 -32768 ~ 32767 unsigned short int unsigned short 2 0 ~ 65535 long int

long 4 -231 ~ 231-1 unsigned long int unsigned long 4 0 ~ 232-1 float 4 double 8 Note: 27 = 128, 215 =32768, 215 = 2147483648 Complex and double complex are not available Dale Roberts Acknowledgements These slides where originally prepared by Dr. Jeffrey Huang, updated by Dale Roberts. Dale Roberts

Recently Viewed Presentations

  • PowerPoint 簡報 - Education Bureau

    PowerPoint 簡報 - Education Bureau

    新高中學音樂科課程 必修部分(必修三個單元) 單元一:聆聽 (40%) 單元二:演奏 i (20%) 單元三:創作 i (20%) 選修部分(選修一個單元)
  • UTE NATIONS MOUNTAIN, SOUTHERN AND NORTHERN By Danielle

    UTE NATIONS MOUNTAIN, SOUTHERN AND NORTHERN By Danielle

    Navajo. Native American Tribes of Utah. (2009). ... Every aspect of life is rooted in spirituality: hunting, songs and dance, ceremonies, war, planting and harvesting of crops, building shelters and crafts ... Video of "Savages" song from Pocahontas showing how...
  • Should I Take Drill Pay or VA Compensation?

    Should I Take Drill Pay or VA Compensation?

    Drill pay is taxable while VA compensation is not. Service members often confuse nontaxable as better. This is not always the case. Each member must make a decision whether to receive drill pay or VA compensation. By law, they cannot...
  • Component-centric Techniques for Accelerating CCD Queries on ...

    Component-centric Techniques for Accelerating CCD Queries on ...

    Radial navigation field have velocities pointing to the center. Tangential navigation field has velocities which take the agents around the Kaaba (and tangential to the obstacles) Increased weight of the radial field causes the agent to draw towards the Kaaba....
  • Presentación de PowerPoint - Facultad Agronomía

    Presentación de PowerPoint - Facultad Agronomía

    Physarum sp. sobre troncos podridos o pastos. Plasmodiophoromycota Mohos mucilaginosos endoparásitos de plantas y Stramenopila Plasmodio intracelular, zoosporas y esporas de reposo Plasmodiophoromycota Plasmodiophora brassicae "club root" Plasmodiophoromycota Spongospora subterranea sarna ...
  • SIGNAL TRANSDUCTION - mbbsclub.com

    SIGNAL TRANSDUCTION - mbbsclub.com

    Direct signaling. is a transfer of ions or small molecules from one cell to its neighbor through pores in the membrane. Those pores are built out of membrane proteins and are called gap junctions.This is the fastest mode of cell-cell...
  • Corpus Linguistics: the basics - Lancaster University

    Corpus Linguistics: the basics - Lancaster University

    Corpus Linguistics Richard Xiao ... Evaluation * Outline of the session Lecture Concordance Patterning Semantic prosody Wordlist Cluster (lexical bundle, MWU, n-gram) Lab WST Concord and Wordlist AntConc Online concordancers Who reads a corpus? A corpus is usually too large...
  • Machine Learning 101 - Network Monitoring and Reporting

    Machine Learning 101 - Network Monitoring and Reporting

    Machine Learning for Advanced Network Monitoring. Develop machine learning techniques for characterizing normal network behavior and detecting anomalies. Use machine learning rather than rule-based methods to be more proactive, actionable and insightful (predictive) Data analysis is performed in data streams...