Binary to Octal and Number Operations
Conversion from Binary to Octal
Overview of Octal System
- The octal number system includes digits from 0 to 7.
- In binary, seven is represented as 111.
Converting Binary to Octal
- Identify the Binary Number: For example, consider the binary number 101101.010110.
- Grouping of Bits: Start grouping the binary digits into groups of three beginning from the radix (decimal point) to the left and right.
- Right of the radix: 010 | 110
- Left of the radix: 101 | 101
- Conversion to Decimal: Convert each group of three to its decimal equivalent:
- Left Groups: 101 (binary) = 5 (decimal), 101 (binary) = 5 (decimal) → 55 (octal).
- Right Groups: 010 (binary) = 2 (decimal), 110 (binary) = 6 (decimal) → 2.6 (octal)
- Final Result: The number in octal is 55.26.
Converting Hexadecimal to Binary and Vice-Versa
- Understanding base conversions involving hexadecimal (hex) and binary is essential.
- Each hex digit corresponds to four binary digits:
- Example: Hex 8 = Binary 1000, Hex 9 = Binary 1001.
- **Converting from Decimal to Hexadecimal: **
- Starting from decimal number 89:
- Break down: 64 (16^1) + 8 (16^0) + 0 (16^-1) + 9 (16^-2) → This leads to hex 59.
Binary Addition
Basic Addition Rules
In binary addition:
- 1 + 1 = 10 (write 0, carry 1).
- 0 + 0 = 0.
- 1 + 0 = 1.
To illustrate:
- Add 1 and 1: yields 0, carry 1.
- Adding a carry can complicate the addition: 111 + 101:
- Process: `
Carry: 1
111
- 101
--------
0 (run this column)
+1 (this carry) +1 (from the next column) gives 11
Current sum: 10 (carry 1)
`
- 101
- Process: `
Carry: 1
111
Adding Multiple Binary Numbers
- Consider adding 1 + 1 + 1:
- This results in carrying over
- Binary Representation of Three = 11 (i.e., write down
1and carry over1).
Representing Negative Binary Numbers
How to Handle Negative Numbers
- Using signed binary for negative values involves a method called two's complement.
- Consider a binary number of four bits, the maximum positive number is 0111 (7).
- Any binary representation with a sign bit reduces the range of representable numbers:
- Range for four bits with sign bit: from -7 to +7.
Two's Complement Conversion Steps
One's Complement: Flip each bit of the binary number:
- Example with 0001 (1): becomes 1110 (in one’s complement).
Add One: Add 1 to the one's complement to get the two's complement:
- Start with 1110:
- (Example: represents -1).
- Start with 1110:
Positive Number Representation: For a positive binary number, write it directly (e.g., 00001111 (15)).
Example of 2's complement for -1:
- As a signed binary in 8 bits, use:
- 00000001 (One) → 11111110 (Flipping bits) → +1 makes it 11111111 (Negative One).
- As a signed binary in 8 bits, use:
Summary of Number Conversion Techniques
- For any conversion between binary, octal, and hexadecimal, practice grouping of bits and know how each system represents values:
- Binary is base 2:
- Octal is base 8:
- Hexadecimal is base 16.
- Familiarity with these bases aids in smooth conversion and arithmetic operations in programming and computer science contexts.