INFO: Negative Values Use Two's Complement (38027)



The information in this article applies to:

  • Microsoft Visual C++ for Windows, 16-bit edition 1.0
  • Microsoft Visual C++ for Windows, 16-bit edition 1.5
  • Microsoft Visual C++, 32-bit Editions 1.0
  • Microsoft Visual C++, 32-bit Editions 2.0
  • Microsoft Visual C++, 32-bit Editions 4.0
  • Microsoft Visual C++, 32-bit Editions 5.0
  • Microsoft Visual C++, 32-bit Editions 6.0

This article was previously published under Q38027

SUMMARY

In most C compilers, including the Microsoft C Compiler, negative values are represented internally in two's complement format. Two's complement can be obtained by negating each bit of the value, then adding 1. Performing two's complement twice generates the original value.

The following is an example:
   Original Value               Two's Complement
   --------------               ----------------

   (dec)   (hex)  (binary)      (dec)   (hex)   (binary)
   127     0x7f   01111111      -127    0x81    10000001
   111     0x6f   01101111      -111    0x91    10010001
  -111     0x91   10010001       111    0x6f    01101111
				

Modification Type:MinorLast Reviewed:7/5/2005
Keywords:kbCompiler kbinfo KB38027