Comprehensive Guide to Binary Arithmetic, Two's Complement, and Hexadecimal Systems
Fundamental Computer Logic and Base Number Systems
Binary Processing in Computers:
Computers process all data exclusively in binary.
This occurs because data processing relies on logic gates, which operate with only two distinct states: or
Base System Definitions:
Denary System: Base- number system (using digits through
Binary System: Base- number system (using digits and
Hexadecimal System: Base- number system (using digits through and letters through
Exactly binary digits (bits) correspond to hexadecimal digit.
Padding Binary Numbers:
When adding extra digits to a binary number to extend it to a full byte (such as an -bit representation), zeros must always be added to the left side of the value, never to the right side.
Binary and Denary Conversions
Binary to Denary Conversion:
Position each binary digit under its corresponding positional base- heading (
Sum the positional values where the bit is set to
Conversion Example: Convert binary to denary:
Denary value =
Denary to Binary Conversion (Successive Division by 2):
Divide the denary integer continuously by
Record the remainder ( or ) at each division step.
Continue division until the quotient is
Write out the remainders from bottom to top (last remainder recorded to first remainder recorded).
Conversion Example: Convert denary to binary:
Binary result (reading remainders bottom to top):
Binary Arithmetic, Overflow, and Shifts
Binary Addition Rules:
(result , carry
(result , carry
Overflow Error:
Definition: Occurs when the result of a calculation exceeds the maximum capacity of the allocated number of bits.
Limits: In an -bit system, the maximum representable denary value is (
Cause: An overflow error happens when a calculation produces a result greater than , which cannot be stored within the available bits.
Binary Shift Operations:
Left Binary Shift:
Moves all bits to the left by a specified number of positions.
Effect: Multiplies the denary value by for each place shifted left.
Example:
Starting value: (
Shifted 1 place left: (
Right Binary Shift:
Moves all bits to the right by a specified number of positions.
Effect: Divides the denary value by for each place shifted right.
Two's Complement Representation
Purpose and Usage:
Two's complement is used to represent negative denary numbers in binary.
Simplifies the architectural implementation of binary subtraction in computers.
Bit Identification:
Most Significant Bit (MSB): The leftmost bit in the sequence.
Least Significant Bit (LSB): The rightmost bit in the sequence.
Positive Denary in Two's Complement:
For positive numbers, the Most Significant Bit (MSB) always remains
Example: Convert positive denary to an -bit Two's complement binary representation:
Place values:
Representation: (, where MSB is
Converting Positive Denary to Negative Denary in Two's Complement:
Convert the positive denary number to standard binary.
Invert all the bits (flip all s to s and all s to s).
Add to the inverted binary result.
Hexadecimal Conversion Methods
Hexadecimal Mapping Table:
Values through are represented as digits to
Denary
Denary
Denary
Denary
Denary
Denary
Binary to Hexadecimal Conversion:
Divide the binary string into groups of bits (nibbles) starting from the right.
Convert each -bit group into its equivalent hexadecimal character.
Conversion Example: Convert to hexadecimal:
Grouping:
Hexadecimal value =
Hexadecimal to Denary Conversion:
Multiply each hexadecimal digit by its corresponding base- positional heading () and sum the products.
Conversion Example: Convert hexadecimal to denary:
Headings:
Hex Digits: (where
Calculation:
Denary value =
Denary to Hexadecimal Conversion (Successive Division by 16):
Divide the denary integer continuously by
Record the remainder at each step, mapping remainders between and to letters through
Read the remainders from bottom to top (last remainder recorded to first remainder recorded).
Conversion Example: Convert denary to hexadecimal:
Hexadecimal value (read bottom to top) =
Practical Applications of Hexadecimal
Error Codes:
Automatically generated by the computer system.
Refer directly to the memory location where an error has occurred.
Media Access Control (MAC) Addresses:
A unique identifier assigned to a network interface controller (NIC) or device on a network.
Made up of bits.
Displayed as groups of hexadecimal digits.
Rarely changed, enabling persistent device identification regardless of network connection location.
IP Addresses (IPv6):
The network address assigned to each device connected to a network.
IPv6 consists of a -bit number broken down into -bit chunks, represented using hexadecimal format.
HTML Color Codes:
Used to specify colors of text and elements on computer displays.
Intensity levels of different color components are defined by hexadecimal values.