# Binary Computers represent integers and do arithmetic with **binary**, base 2, expansions of integers. ![[Binary-1.png]] ## The Sign Bit **Unsigned** binary numbers do not have a *sign bit*. As a result, the *MSB* will be *part of the value* itself rather than a positive/negative indicator. To represent a negative number in binary, we can use a **sign bit** which is always the *MSB* (the digit *furthest to the left*. The rest of the digits represent the number’s **magnitude** (also known as the absolute value or distance from zero). - The range of values that can be held is lowered as a result as we must dedicate a bit to storing the sign information. > When you are given a binary number in the Sign-Magnitude format, **DO NOT** include the *MSB* when placing the bits into the [[number systems#base conversion|conversion equation]]. ## One’s Complement In the **1’s Complement** representation, every *negative number* is the *bitwise inverse* of it’s positive counterpart. In this representation, the *MSB* is the *sign bit* and indicates whether the number is positive or negative: - A *0* means the number is *positive* → *No modifications* need to be made to find the magnitude. - A *1* means the number is *negative* → *Perform a bitwise inverse* to see the magnitude of the number. When you attempt to add the negative and positive versions of a number in this representation, you will end up with `11111...` ## Two’s Complement 2’s Complement is the standard representation for negative numbers. Similarly to the last two representations, the *MSB* represents the *sign bit*. To convert between positive and negative values, we calculate a bitwise inverse and add 1 to the result. - **Binary to Decimal** - An MSB of *1* means the number is *negative* → First, *perform a bitwise inverse* to find the 1’s Complement, next, subtract 1 (to find the magnitude - An MSB of *0* means the number is *positive* → *No modifications* need to be made to find the magnitude. - **Decimal to Binary** The first bit is the sign bit Perfor ## Binary Operations ### Sign Extensions When increasing the bit length of a binary number: - For positive numbers, fill the empty space with 0’s - For negative numbers, fill the empty space with 1’s ### Binary Addition Binary numbers can be added the same way decimal numbers are added. - When ![[Integers.jpg]] ### Binary Substraction ### Binary Multiplication https://www.cuemath.com/numbers/binary-multiplication/ ## Binary Overflow Overflow occurs when adding whenever: - 2 positive numbers are added and the result is negative - 2 negative numbers are added and the result is positive One easy method for spotting overflow is to compare the “Carry In” of the most significant bit (MSB) to the “Carry Out”. If they are different, then overflow has occurred. ![[Binary.png|400]]