# Using Binary

## Using Binary

## Understanding Binary

**Binary**, also known as**base-2**, is a binary numeral system or language used by computer devices. Each digit is referred to as a**bit**.- A byte is made up of 8 bits.
- Binary is used inside a computer as it works using
**logic gates**, and it’s simpler to use a system based on two states – 1 (on) and 0 (off).

## Converting Decimal to Binary

- For converting
**decimal to binary**, start with the highest power of 2 that goes into the decimal number and work down to 2^0. - Mark a 1 under each power of 2 that goes into the original number and 0 where it doesn’t.
- Write out these 1’s and 0’s in the same line and this is your binary number.

## Converting Binary to Decimal

- For converting
**binary to decimal**, multiply each binary digit by the corresponding power of 2. - The rightmost bit represents 2^0, the next one to the left 2^1, then 2^2, etc.
- Sum all these products and the result will be the decimal equivalent of your binary number.

## Binary Arithmetic

**Binary addition and subtraction**follow similar rules as decimals.- 0 + 0 is 0, 0 + 1 or 1 + 0 is 1, 1 + 1 is 10 (which is ‘2’ in decimal but ‘10’ in binary).
- When you add 1 + 1, the ‘1’ carried forward is added to the bits in the next column.
- In binary subtraction, borrow from the next column if the subtrahend is larger than the minuend, similar to the decimal system.

## Binary Shifts

- Binary shifts involve moving all bits in a binary number to the
**left**or**right**and filling the gaps with 0’s. - A left shift
**multiplies a binary number by 2**and a right shift**divides a number by 2**(ignoring remainders). - They can be used for efficient multiplication or division by powers of 2.