SlideShare a Scribd company logo
1 of 11
Exam Sched

Thurs (july 19)
Computer Fundamentals
Physics *lab

Fri (july 20)
English
Calculus

Mon (july 23)
Humanities

Tues (july 24)
PE
Sociology and anthropology




Programming


2's Complement Representation for Signed Integers
     Definition
     Calculation of 2's Complement
     Addition
     Subtraction
     Multiplication
     Division
     Sign Extension
     Other Signed Representations
     Notes




Definition

Property
       Two's complement representation allows the use of binary arithmetic operations on signed
       integers, yielding the correct 2's complement results.
Positive Numbers
       Positive 2's complement numbers are represented as the simple binary.
Negative Numbers
Negative 2's complement numbers are represented as the binary number that when added to
        positive number of the same magnitude equals zero.
        Integer
                       2's Complement
 Signed    Unsigned


    5             5       0000 0101

    4             4       0000 0100

    3             3       0000 0011

    2             2       0000 0010

    1             1       0000 0001

    0             0       0000 0000

   -1          255        1111 1111

   -2          254        1111 1110

   -3          253        1111 1101

   -4          252        1111 1100

   -5          251        1111 1011
Note: The most significant (leftmost) bit indicates the sign of the integer; therefore it is sometimes calle
the sign bit.
       If the sign bit is zero,
       then the number is greater than or equal to zero, or positive.
       If the sign bit is one,
       then the number is less than zero, or negative.


Calculation of 2's Complement

To calculate the 2's complement of an integer, invert the binary equivalent of the number by changin
all of the ones to zeroes and all of the zeroes to ones (also called 1's complement), and then add one

For example,

0001 0001(binary 17)    1110 1111(two's complement -17)


        NOT(0001 0001) = 1110 1110 (Invert bits)
1110 1110 + 0000 0001 = 1110 1111 (Add 1)
2's Complement Addition

Two's complement addition follows the same rules as binary addition.

For example,

5 + (-3) = 2        0000 0101   = +5
                   + 1111 1101 = -3

                    0000 0010   = +2



2's Complement Subtraction

Two's complement subtraction is the binary addition of the minuend to the 2's complement of the
subtrahend (adding a negative number is the same as subtracting a positive one).

For example,

7 - 12 = (-5)       0000 0111   = +7
                   + 1111 0100 = -12

                    1111 1011   = -5



2's Complement Multiplication

Two's complement multiplication follows the same rules as binary multiplication.

For example,

(-4) × 4 = (-16)       1111 1100   = -4
                      × 0000 0100 = +4

                       1111 0000   = -16



2's Complement Division

Two's complement division is repeated 2's complement subtraction. The 2's complement of the divisor
calculated, then added to the dividend. For the next subtraction cycle, the quotient replaces the
dividend. This repeats until the quotient is too small for subtraction or is zero, then it becomes the
remainder. The final answer is the total of subtraction cycles plus the remainder.

For example,

7 ÷ 3 = 2 remainder 1        0000 0111    = +7      0000 0100   = +4
                           + 1111 1101 = -3       + 1111 1101 = -3

                             0000 0100    = +4      0000 0001   = +1 (remainder)



Sign Extension

To extend a signed integer from 8 bits to 16 bits or from 16 bits to 32 bits, append additional bits on the
side of the number. Fill each extra bit with the value of the smaller number's most significant bit (the sig
bit).

For example,


 Signed Integer    8-bit Representation   16-bit Representation


        -1              1111 1111          1111 1111 1111 1111

       +1               0000 0001          0000 0000 0000 0001



Other Representations of Signed Integers

Sign-Magnitude Representation
      Another method of representing negative numbers is sign-magnitude. Sign-magnitude
      representation also uses the most significant bit of the number to indicate the sign. A negative
      number is the 7-bit binary representation of the positive number with the most significant bit set
      one. The drawbacks to using this method for arithmetic computation are that a different set of
      rules are required and that zero can have two representations (+0, 0000 0000 and -0, 1000 0000)

Offset Binary Representation
       A third method for representing signed numbers is offset binary. Begin calculating a offset binar
       code by assigning half of the largest possible number as the zero value. A positive integer is the
       absolute value added to the zero number and a negative integer is subtracted. Offset binary is
       popular in A/D and D/A conversions, but it is still awkward for arithmetic computation.

       For example,

       Largest value for 8-bit integer = 28 = 256
Offset binary zero value = 256 ÷ 2 = 128(decimal) = 1000 0000(binary)

          1000 0000(offset binary 0) + 0001 0110(binary 22) = 1001 0110(offset binary +22)
          1000 0000(offset binary 0) - 0000 0111(binary 7) = 0111 1001(offset binary -7)
 Signed Integer             Sign Magnitude     Offset Binary


           +5                  0000 0101        1000 0101

           +4                  0000 0100        1000 0100

           +3                  0000 0011        1000 0011

           +2                  0000 0010        1000 0010

           +1                  0000 0001        1000 0001

                               0000 0000
            0                                   1000 0000
                               1000 0000

           -1                  1000 0001        0111 1111

           -2                  1000 0010        0111 1110

           -3                  1000 0011        0111 1101

           -4                  1000 0100        0111 1100

           -5                  1000 0101        0111 1011



Notes

Other Complements
      1's Complement = NOT(n) = 1111 1111 - n
      9's Complement = 9999 9999 - n
      10's Complement = (9999 9999 - n) + 1



Two's Complement
Thomas Finley, April 2000



Contents and Introduction
          Contents and Introduction

          Conversion from Two's Complement
Conversion to Two's Complement

            Arithmetic with Two's Complement

            Why Inversion and Adding One Works

Two's complement is not a complicated scheme and is not well served by anything lengthly. Therefore, after this introduction, which explains
what two's complement is and how to use it, there are mostly examples.

Two's complement is the way every computer I know of chooses to represent integers. To get the two's complement negative notation of an
integer, you write out the number in binary. You then invert the digits, and add one to the result.

Suppose we're working with 8 bit quantities (for simplicity's sake) and suppose we want to find how -28 would be expressed in two's
complement notation. First we write out 28 in binary form.


00011100

Then we invert the digits. 0 becomes 1, 1 becomes 0.


11100011

Then we add 1.


11100100

That is how one would write -28 in 8 bit binary.



Conversion from Two's Complement
Use the number 0xFFFFFFFF as an example. In binary, that is:


1111            1111         1111           1111           1111           1111           1111           1111

What can we say about this number? It's first (leftmost) bit is 1, which means that this represents a number that is negative. That's just the
way that things are in two's complement: a leading 1 means the number is negative, a leading 0 means the number is 0 or positive.

To see what this number is a negative of, we reverse the sign of this number. But how to do that? The class notes say (on 3.17) that to
reverse the sign you simply invert the bits (0 goes to 1, and 1 to 0) and add one to the resulting number.

The inversion of that binary number is, obviously:


0000            0000         0000           0000           0000           0000           0000           0000
Then we add one.

0000            0000         0000           0000           0000           0000           0000           0001

So the negative of 0xFFFFFFFF is 0x00000001, more commonly known as 1. So 0xFFFFFFFF is -1.



Conversion to Two's Complement
Note that this works both ways. If you have -30, and want to represent it in 2's complement, you take the binary representation of 30:


0000            0000         0000           0000           0000           0000           0001           1110

Invert the digits.
1111            1111           1111            1111           1111        1111           1110           0001

And add one.


1111            1111           1111            1111           1111        1111           1110           0010

Converted back into hex, this is 0xFFFFFFE2. And indeed, suppose you have this code:


            #include <stdio.h>

            int main() {
                int myInt;
                myInt = 0xFFFFFFE2;
                printf("%dn",myInt);

                     return 0;
            }

That should yield an output of -30. Try it out if you like.



Arithmetic with Two's Complement
One of the nice properties of two's complement is that addition and subtraction is made very simple. With a system like two's complement,
the circuitry for addition and subtraction can be unified, whereas otherwise they would have to be treated as separate operations.


In the examples in this section, I do addition and subtraction in two's complement, but you'll notice that every time I do actual operations with
binary numbers I am always adding.


Example 1
Suppose we want to add two numbers 69 and 12 together. If we're to use decimal, we see the sum is 81. But let's use binary instead, since
that's what the computer uses.



                                                                                                                 1     1
                                                                                                                           Carry Row


      0000            0000           0000            0000        0000           0000           0100           0101
                                                                                                                           (69)


+     0000            0000           0000            0000        0000           0000           0000           1100
                                                                                                                           (12)



      0000            0000           0000            0000        0000           0000           0101           0001
                                                                                                                           (81)


Example 2
Now suppose we want to subtract 12 from 69. Now, 69 - 12 = 69 + (-12). To get the negative of 12 we take its binary representation, invert,
and add one.


0000            0000           0000            0000           0000        0000           0000           1100

Invert the digits.
1111           1111           1111            1111          1111           1111           1111           0011

And add one.


1111           1111           1111            1111          1111           1111           1111           0100

The last is the binary representation for -12. As before, we'll add the two numbers together.



               1111           1111            1111          1111           1111           1111           1              1
                                                                                                                            Carry Row


      0000           0000            0000          0000           0000           0000           0100           0101
                                                                                                                            (69)


+     1111           1111            1111          1111           1111           1111           1111           0100
                                                                                                                            (-12)



      0000           0000            0000          0000           0000           0000           0011           1001
                                                                                                                            (57)


We result in 57, which is 69-12.


Example 3
Lastly, we'll subtract 69 from 12. Similar to our operation in example 2, 12 - 69 = 12 + (- 69). The two's complement representation of 69 is
the following. I assume you've had enough illustrations of inverting and adding one.


1111           1111           1111            1111          1111           1111           1011           1011
So we add this number to 12.



                                                                                                                  111
                                                                                                                            Carry Row


      0000           0000            0000          0000           0000           0000           0000           1100
                                                                                                                            (12)


+     1111           1111            1111          1111           1111           1111           1011           1011
                                                                                                                            (-69)



      1111           1111            1111          1111           1111           1111           1100           0111
                                                                                                                            (-57)


This results in 12 - 69 = -57, which is correct.



Why Inversion and Adding One Works
Invert and add one. Invert and add one. It works, and you may want to know why. If you don't care, skip this, as it is hardly essential. This is
only intended for those curious as to why that rather strange technique actually makes mathematical sense.


Inverting and adding one might sound like a stupid thing to do, but it's actually just a mathematical shortcut of a rather straightforward
computation.


Borrowing and Subtraction
Remember the old trick we learned in first grade of "borrowing one's" from future ten's places to perform a subtraction? You may not, so I'll
go over it. As an example, I'll do 93702 minus 58358.


             93702
           - 58358
           -------

Now, then, what's the answer to this computation? We'll start at the least significant digit, and subtract term by term. We can't subtract 8 from
2, so we'll borrow a digit from the next most significant place (the tens place) to make it 12 minus 8. 12 minus 8 is 4, and we note a 1 digit
above the ten's column to signify that we must remember to subtract by one on the next iteration.


                1
             93702
           - 58358
           -------
                  4

This next iteration is 0 minus 5, and minus 1, or 0 minus 6. Again, we can't do 0 minus 6, so we borrow from the next most significant figure
once more to make that 10 minus 6, which is 4.


               11
             93702
           - 58358
           -------
                44

This next iteration is 7 minus 3, and minus 1, or 7 minus 4. This is 3. We don't have to borrow this time.


               11
             93702
           - 58358
           -------
               344

This next iteration is 3 minus 8. Again, we must borrow to make thi 13 minus 8, or 5.


             1 11
             93702
           - 58358
           -------
              5344

This next iteration is 9 minus 5, and minus 1, or 9 minus 6. This is 3. We don't have to borrow this time.


             1 11
             93702
           - 58358
           -------
             35344

So 93702 minus 58358 is 35344.


Borrowing and it's Relevance to the Negative of a Number
When you want to find the negative of a number, you take the number, and subtract it from zero. Now, suppose we're really stupid, like a
computer, and instead of simply writing a negative sign in front of a number A when we subtract A from 0, we actually go through the steps of
subtracting A from 0.

Take the following idiotic computation of 0 minus 3:



                                          1                          11                        111                        1111
           000000                     000000                      000000                     000000                     000000
           -    3                     -     3                     -     3                    -     3                    -      3
           ------                     ------                      ------                     ------                     ------
                                            7                         97                        997                        9997


Et cetera, et cetera. We'd wind up with a number composed of a 7 in the one's digit, a 9 in every digit more significant than the 100's place.


The Same in Binary
We can do more or less the same thing with binary. In this example I use 8 bit binary numbers, but the principle is the same for both 8 bit
binary numbers (chars) and 32 bit binary numbers (ints). I take the number 75 (in 8 bit binary that is 010010112) and subtract that from zero.

Sometimes I am in the position where I am subtracting 1 from zero, and also subtracting another borrowed 1 against it.




                                         1                             11                            111                           1111

           0000000                       0000000                       0000000                       0000000                       0000000
           0                             0                             0                             0                             0
           -                             -                             -                             -                             -
           0100101                       0100101                       0100101                       0100101                       0100101
           1                             1                             1                             1                             1
           -------                       -------                       -------                       -------                       -------
           ---                           ---                           ---                           ---                           ---

                                         1                             01                            101                           0101


                                                                                                     1111111
           11111                         111111                        1111111                       1

           0000000                       0000000                       0000000                       0000000
           0                             0                             0                             0
           -                             -                             -                             -
           0100101                       0100101                       0100101                       0100101
           1                             1                             1                             1
           -------                       -------                       -------                       -------
           ---                           ---                           ---                           ---

           10101                         110101                        0110101                       1011010
                                                                                                     1


If we wanted we could go further, but there would be no point. Inside of a computer the result of this computation would be assigned to an
eight bit variable, so any bits beyond the eighth would be discarded.
With the fact that we'll simply disregard any extra digits in mind, what difference would it make to the end result to have subtracted 01001011
from 100000000 (a one bit followed by 8 zero bits) rather than 0? There is none. If we do that, we wind up with the same result:


            11111111
            100000000
           - 01001011
           ----------
            010110101

So to find the negative of an n-bit number in a computer, subtract the number from 0 or subtract it from 2n. In binary, this power of two will be
a one bit followed by n zero bits.

In the case of 8-bit numbers, it will answer just as well if we subtract our number from (1 + 11111111) rather than 100000000.


                    1
           + 11111111
           - 01001011
           ----------

In binary, when we subtract a number A from a number of all 1 bits, what we're doing is inverting the bits of A. So the subtract operation is
the equivalent of inverting the bits of the number. Then, we add one.

So, to the computer, taking the negative of a number, that is, subtracting a number from 0, is the same as inverting the bits and adding one,
which is where the trick comes from.




Thomas Finley 2000

More Related Content

What's hot (20)

Integer Representation
Integer RepresentationInteger Representation
Integer Representation
 
Representation of Negative Numbers
Representation of Negative NumbersRepresentation of Negative Numbers
Representation of Negative Numbers
 
Binary Arithmetic
Binary ArithmeticBinary Arithmetic
Binary Arithmetic
 
Floating point arithmetic operations (1)
Floating point arithmetic operations (1)Floating point arithmetic operations (1)
Floating point arithmetic operations (1)
 
Number System
Number SystemNumber System
Number System
 
Number system
Number systemNumber system
Number system
 
Computer arithmetic
Computer arithmeticComputer arithmetic
Computer arithmetic
 
Division algorithm
Division algorithmDivision algorithm
Division algorithm
 
BINARY NUMBER SYSTEM
BINARY NUMBER SYSTEMBINARY NUMBER SYSTEM
BINARY NUMBER SYSTEM
 
Number system conversion
Number system conversionNumber system conversion
Number system conversion
 
1’s and 2’s complements
1’s and 2’s complements1’s and 2’s complements
1’s and 2’s complements
 
11 octal number system
11   octal number system11   octal number system
11 octal number system
 
Bcd
BcdBcd
Bcd
 
Multiplication algorithm
Multiplication algorithmMultiplication algorithm
Multiplication algorithm
 
Decimal number system
Decimal number systemDecimal number system
Decimal number system
 
2s complement arithmetic
2s complement arithmetic2s complement arithmetic
2s complement arithmetic
 
Decimal adder
Decimal adderDecimal adder
Decimal adder
 
Binary arithmetic
Binary arithmeticBinary arithmetic
Binary arithmetic
 
Complement
ComplementComplement
Complement
 
Number system
Number systemNumber system
Number system
 

Viewers also liked

Math1003 1.15 - Integers and 2's Complement
Math1003 1.15 - Integers and 2's ComplementMath1003 1.15 - Integers and 2's Complement
Math1003 1.15 - Integers and 2's Complementgcmath1003
 
Math1003 - An Intro to Number Systems
Math1003 - An Intro to Number SystemsMath1003 - An Intro to Number Systems
Math1003 - An Intro to Number Systemsgcmath1003
 
Introduction number systems and conversion
 Introduction number systems and conversion Introduction number systems and conversion
Introduction number systems and conversionkanyuma jitjumnong
 
Lecture 6 adder (hardware circuit)
Lecture 6   adder (hardware circuit)Lecture 6   adder (hardware circuit)
Lecture 6 adder (hardware circuit)Pradeep Kumar TS
 
Ranjak Vaidic Ganit Preview (Marathi Research Book)
Ranjak Vaidic Ganit Preview (Marathi Research Book)Ranjak Vaidic Ganit Preview (Marathi Research Book)
Ranjak Vaidic Ganit Preview (Marathi Research Book)Vitthal Jadhav
 
Operating Systems 1 (7/12) - Threads
Operating Systems 1 (7/12) - ThreadsOperating Systems 1 (7/12) - Threads
Operating Systems 1 (7/12) - ThreadsPeter Tröger
 
Photochromatic lenses and tints www.eyenirvaan.com
Photochromatic lenses and tints   www.eyenirvaan.comPhotochromatic lenses and tints   www.eyenirvaan.com
Photochromatic lenses and tints www.eyenirvaan.comEyenirvaan
 
Thread presentation
Thread presentationThread presentation
Thread presentationAAshish Ojha
 
Ch5: Threads (Operating System)
Ch5: Threads (Operating System)Ch5: Threads (Operating System)
Ch5: Threads (Operating System)Ahmar Hashmi
 
Operating System Chapter 4 Multithreaded programming
Operating System Chapter 4 Multithreaded programmingOperating System Chapter 4 Multithreaded programming
Operating System Chapter 4 Multithreaded programmingguesta40f80
 
number system school ppt ninth class
number system school ppt ninth classnumber system school ppt ninth class
number system school ppt ninth classManan Jain
 

Viewers also liked (20)

Two’s complement
Two’s complementTwo’s complement
Two’s complement
 
Math1003 1.15 - Integers and 2's Complement
Math1003 1.15 - Integers and 2's ComplementMath1003 1.15 - Integers and 2's Complement
Math1003 1.15 - Integers and 2's Complement
 
Math1003 - An Intro to Number Systems
Math1003 - An Intro to Number SystemsMath1003 - An Intro to Number Systems
Math1003 - An Intro to Number Systems
 
Introduction number systems and conversion
 Introduction number systems and conversion Introduction number systems and conversion
Introduction number systems and conversion
 
Lecture 6 adder (hardware circuit)
Lecture 6   adder (hardware circuit)Lecture 6   adder (hardware circuit)
Lecture 6 adder (hardware circuit)
 
Digital logic mohammed salim ch2
Digital logic mohammed salim ch2Digital logic mohammed salim ch2
Digital logic mohammed salim ch2
 
Al2ed chapter11
Al2ed chapter11Al2ed chapter11
Al2ed chapter11
 
Ranjak Vaidic Ganit Preview (Marathi Research Book)
Ranjak Vaidic Ganit Preview (Marathi Research Book)Ranjak Vaidic Ganit Preview (Marathi Research Book)
Ranjak Vaidic Ganit Preview (Marathi Research Book)
 
Main Memory
Main MemoryMain Memory
Main Memory
 
OS - Thread
OS - ThreadOS - Thread
OS - Thread
 
Photochromic Lens
Photochromic LensPhotochromic Lens
Photochromic Lens
 
Operating Systems 1 (7/12) - Threads
Operating Systems 1 (7/12) - ThreadsOperating Systems 1 (7/12) - Threads
Operating Systems 1 (7/12) - Threads
 
Photochromatic lenses and tints www.eyenirvaan.com
Photochromatic lenses and tints   www.eyenirvaan.comPhotochromatic lenses and tints   www.eyenirvaan.com
Photochromatic lenses and tints www.eyenirvaan.com
 
Thread presentation
Thread presentationThread presentation
Thread presentation
 
Ch5: Threads (Operating System)
Ch5: Threads (Operating System)Ch5: Threads (Operating System)
Ch5: Threads (Operating System)
 
Operating System Chapter 4 Multithreaded programming
Operating System Chapter 4 Multithreaded programmingOperating System Chapter 4 Multithreaded programming
Operating System Chapter 4 Multithreaded programming
 
Threads
ThreadsThreads
Threads
 
Structure chart
Structure chartStructure chart
Structure chart
 
Processes and threads
Processes and threadsProcesses and threads
Processes and threads
 
number system school ppt ninth class
number system school ppt ninth classnumber system school ppt ninth class
number system school ppt ninth class
 

Similar to 2's complement

Similar to 2's complement (20)

Binaty Arithmetic and Binary coding schemes
Binaty Arithmetic and Binary coding schemesBinaty Arithmetic and Binary coding schemes
Binaty Arithmetic and Binary coding schemes
 
Chapter 2_Number system (EEEg4302).pdf
Chapter 2_Number system (EEEg4302).pdfChapter 2_Number system (EEEg4302).pdf
Chapter 2_Number system (EEEg4302).pdf
 
unit-2_DL.pdf
unit-2_DL.pdfunit-2_DL.pdf
unit-2_DL.pdf
 
ch2.pdf
ch2.pdfch2.pdf
ch2.pdf
 
3.Fixed-Floating Point.ppt
3.Fixed-Floating Point.ppt3.Fixed-Floating Point.ppt
3.Fixed-Floating Point.ppt
 
Mba admission in india
Mba admission in indiaMba admission in india
Mba admission in india
 
Chapter 2 Data Representation on CPU (part 1)
Chapter 2 Data Representation on CPU (part 1)Chapter 2 Data Representation on CPU (part 1)
Chapter 2 Data Representation on CPU (part 1)
 
B sc ii sem unit 2(a) ns
B sc ii sem  unit 2(a) nsB sc ii sem  unit 2(a) ns
B sc ii sem unit 2(a) ns
 
B sc3 unit 2 number system
B sc3  unit 2 number systemB sc3  unit 2 number system
B sc3 unit 2 number system
 
Slide03 Number System and Operations Part 1
Slide03 Number System and Operations Part 1Slide03 Number System and Operations Part 1
Slide03 Number System and Operations Part 1
 
Mba admission in india
Mba admission in indiaMba admission in india
Mba admission in india
 
Chapter 02 Data Types
Chapter 02   Data TypesChapter 02   Data Types
Chapter 02 Data Types
 
Pp02
Pp02Pp02
Pp02
 
Alu1
Alu1Alu1
Alu1
 
Number system
Number systemNumber system
Number system
 
Data Representation
Data RepresentationData Representation
Data Representation
 
09 Arithmetic
09  Arithmetic09  Arithmetic
09 Arithmetic
 
Convertion of single precision
Convertion of single precisionConvertion of single precision
Convertion of single precision
 
Data Representation
Data RepresentationData Representation
Data Representation
 
FYBSC IT Digital Electronics Unit I Chapter II Number System and Binary Arith...
FYBSC IT Digital Electronics Unit I Chapter II Number System and Binary Arith...FYBSC IT Digital Electronics Unit I Chapter II Number System and Binary Arith...
FYBSC IT Digital Electronics Unit I Chapter II Number System and Binary Arith...
 

More from Arvenz Gavino (20)

Kuya modesto3
Kuya modesto3Kuya modesto3
Kuya modesto3
 
L
LL
L
 
Kuya rafael3
Kuya rafael3Kuya rafael3
Kuya rafael3
 
Kuya rafael2
Kuya rafael2Kuya rafael2
Kuya rafael2
 
Kuya modesto3
Kuya modesto3Kuya modesto3
Kuya modesto3
 
Kuya modesto2
Kuya modesto2Kuya modesto2
Kuya modesto2
 
Kuya modesto1
Kuya modesto1Kuya modesto1
Kuya modesto1
 
Kuya rafael
Kuya rafaelKuya rafael
Kuya rafael
 
Y
YY
Y
 
My visit in manila is one thing unforgettable
My visit in manila is one thing unforgettableMy visit in manila is one thing unforgettable
My visit in manila is one thing unforgettable
 
Music has a magic that is unexplainable
Music has a magic that is unexplainableMusic has a magic that is unexplainable
Music has a magic that is unexplainable
 
Legend
LegendLegend
Legend
 
Human1
Human1Human1
Human1
 
The mx
The mxThe mx
The mx
 
Heat transfer
Heat transferHeat transfer
Heat transfer
 
Doc
DocDoc
Doc
 
Lec 7 elements_of_the_state
Lec 7 elements_of_the_stateLec 7 elements_of_the_state
Lec 7 elements_of_the_state
 
Lec 6 philippines2
Lec 6 philippines2Lec 6 philippines2
Lec 6 philippines2
 
Lec 7 elements_of_the_state
Lec 7 elements_of_the_stateLec 7 elements_of_the_state
Lec 7 elements_of_the_state
 
Lec 7 filipino_values
Lec 7 filipino_valuesLec 7 filipino_values
Lec 7 filipino_values
 

Recently uploaded

TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 

Recently uploaded (20)

TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 

2's complement

  • 1. Exam Sched Thurs (july 19) Computer Fundamentals Physics *lab Fri (july 20) English Calculus Mon (july 23) Humanities Tues (july 24) PE Sociology and anthropology Programming 2's Complement Representation for Signed Integers  Definition  Calculation of 2's Complement  Addition  Subtraction  Multiplication  Division  Sign Extension  Other Signed Representations  Notes Definition Property Two's complement representation allows the use of binary arithmetic operations on signed integers, yielding the correct 2's complement results. Positive Numbers Positive 2's complement numbers are represented as the simple binary. Negative Numbers
  • 2. Negative 2's complement numbers are represented as the binary number that when added to positive number of the same magnitude equals zero. Integer 2's Complement Signed Unsigned 5 5 0000 0101 4 4 0000 0100 3 3 0000 0011 2 2 0000 0010 1 1 0000 0001 0 0 0000 0000 -1 255 1111 1111 -2 254 1111 1110 -3 253 1111 1101 -4 252 1111 1100 -5 251 1111 1011 Note: The most significant (leftmost) bit indicates the sign of the integer; therefore it is sometimes calle the sign bit. If the sign bit is zero, then the number is greater than or equal to zero, or positive. If the sign bit is one, then the number is less than zero, or negative. Calculation of 2's Complement To calculate the 2's complement of an integer, invert the binary equivalent of the number by changin all of the ones to zeroes and all of the zeroes to ones (also called 1's complement), and then add one For example, 0001 0001(binary 17) 1110 1111(two's complement -17) NOT(0001 0001) = 1110 1110 (Invert bits) 1110 1110 + 0000 0001 = 1110 1111 (Add 1)
  • 3. 2's Complement Addition Two's complement addition follows the same rules as binary addition. For example, 5 + (-3) = 2 0000 0101 = +5 + 1111 1101 = -3 0000 0010 = +2 2's Complement Subtraction Two's complement subtraction is the binary addition of the minuend to the 2's complement of the subtrahend (adding a negative number is the same as subtracting a positive one). For example, 7 - 12 = (-5) 0000 0111 = +7 + 1111 0100 = -12 1111 1011 = -5 2's Complement Multiplication Two's complement multiplication follows the same rules as binary multiplication. For example, (-4) × 4 = (-16) 1111 1100 = -4 × 0000 0100 = +4 1111 0000 = -16 2's Complement Division Two's complement division is repeated 2's complement subtraction. The 2's complement of the divisor calculated, then added to the dividend. For the next subtraction cycle, the quotient replaces the
  • 4. dividend. This repeats until the quotient is too small for subtraction or is zero, then it becomes the remainder. The final answer is the total of subtraction cycles plus the remainder. For example, 7 ÷ 3 = 2 remainder 1 0000 0111 = +7 0000 0100 = +4 + 1111 1101 = -3 + 1111 1101 = -3 0000 0100 = +4 0000 0001 = +1 (remainder) Sign Extension To extend a signed integer from 8 bits to 16 bits or from 16 bits to 32 bits, append additional bits on the side of the number. Fill each extra bit with the value of the smaller number's most significant bit (the sig bit). For example, Signed Integer 8-bit Representation 16-bit Representation -1 1111 1111 1111 1111 1111 1111 +1 0000 0001 0000 0000 0000 0001 Other Representations of Signed Integers Sign-Magnitude Representation Another method of representing negative numbers is sign-magnitude. Sign-magnitude representation also uses the most significant bit of the number to indicate the sign. A negative number is the 7-bit binary representation of the positive number with the most significant bit set one. The drawbacks to using this method for arithmetic computation are that a different set of rules are required and that zero can have two representations (+0, 0000 0000 and -0, 1000 0000) Offset Binary Representation A third method for representing signed numbers is offset binary. Begin calculating a offset binar code by assigning half of the largest possible number as the zero value. A positive integer is the absolute value added to the zero number and a negative integer is subtracted. Offset binary is popular in A/D and D/A conversions, but it is still awkward for arithmetic computation. For example, Largest value for 8-bit integer = 28 = 256
  • 5. Offset binary zero value = 256 ÷ 2 = 128(decimal) = 1000 0000(binary) 1000 0000(offset binary 0) + 0001 0110(binary 22) = 1001 0110(offset binary +22) 1000 0000(offset binary 0) - 0000 0111(binary 7) = 0111 1001(offset binary -7) Signed Integer Sign Magnitude Offset Binary +5 0000 0101 1000 0101 +4 0000 0100 1000 0100 +3 0000 0011 1000 0011 +2 0000 0010 1000 0010 +1 0000 0001 1000 0001 0000 0000 0 1000 0000 1000 0000 -1 1000 0001 0111 1111 -2 1000 0010 0111 1110 -3 1000 0011 0111 1101 -4 1000 0100 0111 1100 -5 1000 0101 0111 1011 Notes Other Complements 1's Complement = NOT(n) = 1111 1111 - n 9's Complement = 9999 9999 - n 10's Complement = (9999 9999 - n) + 1 Two's Complement Thomas Finley, April 2000 Contents and Introduction Contents and Introduction Conversion from Two's Complement
  • 6. Conversion to Two's Complement Arithmetic with Two's Complement Why Inversion and Adding One Works Two's complement is not a complicated scheme and is not well served by anything lengthly. Therefore, after this introduction, which explains what two's complement is and how to use it, there are mostly examples. Two's complement is the way every computer I know of chooses to represent integers. To get the two's complement negative notation of an integer, you write out the number in binary. You then invert the digits, and add one to the result. Suppose we're working with 8 bit quantities (for simplicity's sake) and suppose we want to find how -28 would be expressed in two's complement notation. First we write out 28 in binary form. 00011100 Then we invert the digits. 0 becomes 1, 1 becomes 0. 11100011 Then we add 1. 11100100 That is how one would write -28 in 8 bit binary. Conversion from Two's Complement Use the number 0xFFFFFFFF as an example. In binary, that is: 1111 1111 1111 1111 1111 1111 1111 1111 What can we say about this number? It's first (leftmost) bit is 1, which means that this represents a number that is negative. That's just the way that things are in two's complement: a leading 1 means the number is negative, a leading 0 means the number is 0 or positive. To see what this number is a negative of, we reverse the sign of this number. But how to do that? The class notes say (on 3.17) that to reverse the sign you simply invert the bits (0 goes to 1, and 1 to 0) and add one to the resulting number. The inversion of that binary number is, obviously: 0000 0000 0000 0000 0000 0000 0000 0000 Then we add one. 0000 0000 0000 0000 0000 0000 0000 0001 So the negative of 0xFFFFFFFF is 0x00000001, more commonly known as 1. So 0xFFFFFFFF is -1. Conversion to Two's Complement Note that this works both ways. If you have -30, and want to represent it in 2's complement, you take the binary representation of 30: 0000 0000 0000 0000 0000 0000 0001 1110 Invert the digits.
  • 7. 1111 1111 1111 1111 1111 1111 1110 0001 And add one. 1111 1111 1111 1111 1111 1111 1110 0010 Converted back into hex, this is 0xFFFFFFE2. And indeed, suppose you have this code: #include <stdio.h> int main() { int myInt; myInt = 0xFFFFFFE2; printf("%dn",myInt); return 0; } That should yield an output of -30. Try it out if you like. Arithmetic with Two's Complement One of the nice properties of two's complement is that addition and subtraction is made very simple. With a system like two's complement, the circuitry for addition and subtraction can be unified, whereas otherwise they would have to be treated as separate operations. In the examples in this section, I do addition and subtraction in two's complement, but you'll notice that every time I do actual operations with binary numbers I am always adding. Example 1 Suppose we want to add two numbers 69 and 12 together. If we're to use decimal, we see the sum is 81. But let's use binary instead, since that's what the computer uses. 1 1 Carry Row 0000 0000 0000 0000 0000 0000 0100 0101 (69) + 0000 0000 0000 0000 0000 0000 0000 1100 (12) 0000 0000 0000 0000 0000 0000 0101 0001 (81) Example 2 Now suppose we want to subtract 12 from 69. Now, 69 - 12 = 69 + (-12). To get the negative of 12 we take its binary representation, invert, and add one. 0000 0000 0000 0000 0000 0000 0000 1100 Invert the digits.
  • 8. 1111 1111 1111 1111 1111 1111 1111 0011 And add one. 1111 1111 1111 1111 1111 1111 1111 0100 The last is the binary representation for -12. As before, we'll add the two numbers together. 1111 1111 1111 1111 1111 1111 1 1 Carry Row 0000 0000 0000 0000 0000 0000 0100 0101 (69) + 1111 1111 1111 1111 1111 1111 1111 0100 (-12) 0000 0000 0000 0000 0000 0000 0011 1001 (57) We result in 57, which is 69-12. Example 3 Lastly, we'll subtract 69 from 12. Similar to our operation in example 2, 12 - 69 = 12 + (- 69). The two's complement representation of 69 is the following. I assume you've had enough illustrations of inverting and adding one. 1111 1111 1111 1111 1111 1111 1011 1011 So we add this number to 12. 111 Carry Row 0000 0000 0000 0000 0000 0000 0000 1100 (12) + 1111 1111 1111 1111 1111 1111 1011 1011 (-69) 1111 1111 1111 1111 1111 1111 1100 0111 (-57) This results in 12 - 69 = -57, which is correct. Why Inversion and Adding One Works Invert and add one. Invert and add one. It works, and you may want to know why. If you don't care, skip this, as it is hardly essential. This is only intended for those curious as to why that rather strange technique actually makes mathematical sense. Inverting and adding one might sound like a stupid thing to do, but it's actually just a mathematical shortcut of a rather straightforward computation. Borrowing and Subtraction
  • 9. Remember the old trick we learned in first grade of "borrowing one's" from future ten's places to perform a subtraction? You may not, so I'll go over it. As an example, I'll do 93702 minus 58358. 93702 - 58358 ------- Now, then, what's the answer to this computation? We'll start at the least significant digit, and subtract term by term. We can't subtract 8 from 2, so we'll borrow a digit from the next most significant place (the tens place) to make it 12 minus 8. 12 minus 8 is 4, and we note a 1 digit above the ten's column to signify that we must remember to subtract by one on the next iteration. 1 93702 - 58358 ------- 4 This next iteration is 0 minus 5, and minus 1, or 0 minus 6. Again, we can't do 0 minus 6, so we borrow from the next most significant figure once more to make that 10 minus 6, which is 4. 11 93702 - 58358 ------- 44 This next iteration is 7 minus 3, and minus 1, or 7 minus 4. This is 3. We don't have to borrow this time. 11 93702 - 58358 ------- 344 This next iteration is 3 minus 8. Again, we must borrow to make thi 13 minus 8, or 5. 1 11 93702 - 58358 ------- 5344 This next iteration is 9 minus 5, and minus 1, or 9 minus 6. This is 3. We don't have to borrow this time. 1 11 93702 - 58358 ------- 35344 So 93702 minus 58358 is 35344. Borrowing and it's Relevance to the Negative of a Number
  • 10. When you want to find the negative of a number, you take the number, and subtract it from zero. Now, suppose we're really stupid, like a computer, and instead of simply writing a negative sign in front of a number A when we subtract A from 0, we actually go through the steps of subtracting A from 0. Take the following idiotic computation of 0 minus 3: 1 11 111 1111 000000 000000 000000 000000 000000 - 3 - 3 - 3 - 3 - 3 ------ ------ ------ ------ ------ 7 97 997 9997 Et cetera, et cetera. We'd wind up with a number composed of a 7 in the one's digit, a 9 in every digit more significant than the 100's place. The Same in Binary We can do more or less the same thing with binary. In this example I use 8 bit binary numbers, but the principle is the same for both 8 bit binary numbers (chars) and 32 bit binary numbers (ints). I take the number 75 (in 8 bit binary that is 010010112) and subtract that from zero. Sometimes I am in the position where I am subtracting 1 from zero, and also subtracting another borrowed 1 against it. 1 11 111 1111 0000000 0000000 0000000 0000000 0000000 0 0 0 0 0 - - - - - 0100101 0100101 0100101 0100101 0100101 1 1 1 1 1 ------- ------- ------- ------- ------- --- --- --- --- --- 1 01 101 0101 1111111 11111 111111 1111111 1 0000000 0000000 0000000 0000000 0 0 0 0 - - - - 0100101 0100101 0100101 0100101 1 1 1 1 ------- ------- ------- ------- --- --- --- --- 10101 110101 0110101 1011010 1 If we wanted we could go further, but there would be no point. Inside of a computer the result of this computation would be assigned to an eight bit variable, so any bits beyond the eighth would be discarded.
  • 11. With the fact that we'll simply disregard any extra digits in mind, what difference would it make to the end result to have subtracted 01001011 from 100000000 (a one bit followed by 8 zero bits) rather than 0? There is none. If we do that, we wind up with the same result: 11111111 100000000 - 01001011 ---------- 010110101 So to find the negative of an n-bit number in a computer, subtract the number from 0 or subtract it from 2n. In binary, this power of two will be a one bit followed by n zero bits. In the case of 8-bit numbers, it will answer just as well if we subtract our number from (1 + 11111111) rather than 100000000. 1 + 11111111 - 01001011 ---------- In binary, when we subtract a number A from a number of all 1 bits, what we're doing is inverting the bits of A. So the subtract operation is the equivalent of inverting the bits of the number. Then, we add one. So, to the computer, taking the negative of a number, that is, subtracting a number from 0, is the same as inverting the bits and adding one, which is where the trick comes from. Thomas Finley 2000