Number Systems
Number Systems
A number system is a writing system for expressing numbers in a consistent manner. It provides
a standard for counting and performing arithmetic operations. Number systems are categorized
based on their base or radix, and the base refers to the number of unique digits used in the
system.
o Used in Everyday Life: Used for most human applications, including counting,
calculations, and financial transactions.
2. Binary Number System (Base-2):
o Used in Computers: Computers use the binary system, which consists of only
two digits: 0 and 1. These correspond to the off and on states of electrical circuits.
o Place Value: Each position represents a power of 2. For example, 1011 (in
binary) can be expressed as:
1. Binary to Decimal:
o For example, converting binary 1010 to decimal:
2. Decimal to Binary:
o To convert decimal 10 to binary, repeatedly divide by 2 and note the remainders:
3. Binary to Hexadecimal:
o Group binary digits into sets of 4 and convert each group to its hexadecimal
equivalent. For example, 11010111 (binary) becomes D7 (hexadecimal).
1. Arithmetic Operations:
o Addition: The ALU adds numbers using binary arithmetic. For example, adding
1101 (13) and 1011 (11) gives 11000 (24) in binary.
o Subtraction: The ALU performs binary subtraction, using techniques like two's
complement to represent negative numbers.
o Multiplication: It can multiply numbers using algorithms like shift-and-add or
Booth's algorithm.
o Division: Similar to multiplication, it uses algorithms to divide binary numbers.
2. Logical Operations:
o AND: The ALU performs a logical AND operation where the result is 1 only if
both operands are 1.
o OR: The ALU performs a logical OR operation where the result is 1 if at least one
operand is 1.
o NOT: The ALU performs a logical NOT operation, flipping the bits (1 becomes 0
and vice versa).
o XOR: The ALU performs a logical XOR operation, where the result is 1 if
exactly one of the operands is 1.
3. Comparison Operations:
o Equal to (==): The ALU checks if two values are equal.
o Greater than (>): The ALU compares two values to see if one is greater than the
other.
o Less than (<): The ALU compares two values to see if one is less than the other.
The ALU is typically composed of several key components that allow it to perform operations:
1. Input Registers:
o The ALU receives input data from registers in the CPU. These inputs are typically
two binary numbers (operands) that will be operated on.
2. Control Unit:
o The control unit of the CPU signals the ALU on which operation to perform
(addition, subtraction, AND, OR, etc.) based on the instruction currently being
executed.
3. Operation Unit:
o The operation unit performs the actual arithmetic or logical operations. For
example, an adder is used for addition, a subtractor for subtraction, and so on.
4. Output:
o After the ALU performs the desired operation, the result is stored in a register or
sent to memory.
5. Flags:
o The ALU may also set flags in a status register based on the outcome of
operations. Common flags include:
Zero Flag (Z): Set if the result is 0.
Carry Flag (C): Set if there’s a carry out from an operation (important for
addition).
Overflow Flag (O): Set if there’s an overflow in an arithmetic operation.
Negative Flag (N): Set if the result is negative.
Let’s take an example of binary addition. Adding 1101 (13) and 1011 (11):
yaml
CopyEdit
1101
1011
11000
markdown
CopyEdit
For **subtraction** using two’s complement, the ALU would invert the bits of
the second operand (the number to be subtracted) and then add 1. This way,
the ALU performs subtraction just like addition, but with the second operand
in its negative form.
Example:
Example:
pgsql
CopyEdit
---
### **Conclusion**