Information Representation

From Rice Wiki
Revision as of 20:23, 2 April 2024 by Admin (talk | contribs)

Inside a computer, everything is bits. The topic of information representation discusses how different information inside a computer program actually looks like in the background.

2's complement is a method of representing integers in computer science.

To calculate the value of a number represented by 2's complement, just think of the first bit in the bit pattern as negative. For example, 101 would be 4 + 1 = 5 as an unsigned number, but -4 + 1 = -3 as a signed number represented by 2's complement.

The advantage of using 2's complement over signed magnitude is twofold:

  • Easier arithmetic operations
  • Greater range of values (since there is no -0)


  • To negate signed numbers, flip all bits and add 1. This comes from math: Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle -2 = -4 + ((4 - 1) - 2) + 1}