Information Representation: Difference between revisions

From Rice Wiki
(Created page with "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. Category:Computer Architecture")
 
No edit summary
Line 1: Line 1:
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.
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: <math>-2 = -4 + ((4 - 1) - 2) + 1</math>
[[Category:Computer Architecture]]
[[Category:Computer Architecture]]

Revision as of 20:23, 2 April 2024

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: