Ironetcart Андроид Ассемблер MASM32 Linux Все статьи Table of Contents


Negative numbers

  Max Petrov May 2013

      A positive number designates a count, this is the quantity of items or the counting number of the item, which cannot be said about the negative number. A negative number, strictly speaking, does not have any numerical meaning, it rather symbolizes a future action. A negative number shows that in the future from the newly appeared items we should subtract a few ones.

      The logical and elegant solution is to represent negative numbers in the form of empty cells. Suppose that there is a set of counting sticks, and it is known the standard number of sticks in the set. After execution of any actions over this set, the remaining sticks in the set will denote a positive number, empty cells will denote a negative number. It is easy to see that with such an approach, any number of sticks in the set symbolizes two numbers at once, both positive and negative. Depending on our agreement, one of these numbers will be explicit, the other implicit.

negative numbers

      The numerical multitude of our set looks unusual, because it has two zeros (Fig.1). Suppose that for our set of countable sticks is fulfilled the following condition: with the maximum number of sticks in the set they disappear, that is, the maximum number of sticks is zero. Then the multitude of numbers, that can display a set, is convenient to represent in form of a ring (Fig.2).

      Just like this the processor sees the numbers, which is easy to verify. For example, we will subtract in a cycle from the byte variable a one in each step. When the value of the variable reaches zero, by the next subtraction we will receive in a variable the value of 255. This is the maximum number that can be written to a byte. By successive subtraction, the number 255 again will be reduced to zero, when we subtract one from zero, we again get 255. This will continue for as long as we want, until we stop the program.

      This principle of work with numbers is in good agreement with the characteristics of computers. The cells (bytes, words, double words, etc.), in which the computer stores the numbers, are finites. In addition, such a principle ensures easy execution of arithmetic operations. For example, the subtraction can be replaced by an addition, if you invert the substracted number. For a byte, i.e. for a set of 256 counting sticks (256 is zero):
      10 - 1 = 10 + 255 = 9
The solution will be 265, but 256 of them should disappear (256 is a unit in the next byte), but 9 will remain. Thus, the computer will receive the correct result.

      Call such a representation of negative numbers by inversion with a complement, that is, to obtain a representation of a negative number, the bits of a compatible with it positive number are inverted, and to the result the one is added. The one is added because the maximum number in the set, in application to the memory cells in the computer, it is convenient to suppose the first number which does not fit in the cell. When this number is reached, zero is obtained automatically and the count starts again.


Send a comment


Insert the digits:

Table of Contents

Assembler MASM32

      The simplest assembly program (beeper)
      Variables and Data Types of Assembler
      Registers of Processor IA32
      Numerical Systems, conversion of number
      Negative numbers

Other articles

      Frontend protection against Stored XSS Attacks (Javascript kills XSS)
      How to enforce Firefox to update favicon
      How to lock CD autorun in Windows XP
      Javascript Progress Bar for PHP program
      Schultz's tables (Shultzstables.exe)
      Speed of Forum Engine. Files or Database
      The best free programs for reading txt-files on Android smartphones
      Why a stupid forum needs a search option?


© Max Petrov При использовании материалов ссылка на обязательна