01-11-2012, 01:53 PM
Bit-wise Operations
Bit-wise.ppt (Size: 106.5 KB / Downloads: 20)
Binary Numbers
Each binary digit represents one of two states
Bit 0 or 1 absence / presence of signal
Each position in a binary number
Represents a power of two
Just as each position in a decimal number represents a power of 10
Conversion techniques
Repeated division by 2
Subtraction by powers of two
Bit-Wise Operations
Operations need to be performed by hardware
Should be easy, accurate, & consistent
Comparison
Set one signal line based on two others
Addition
Subtraction, add the negative number
Multiplication
Repeated Addition
Division, reverse the process !?!
Left Shift
Every bit gets moved one position to the left
The most significant bit is lost
A zero is inserted on the right
Same as multiplying by 2
Just like multiplying decimal numbers by 10
Since our positions represent powers of 2
moving a bit to the left makes it twice as big
Other Shifts
Not Supported by Java
We'd have to program these
Barrel Shift
Barrel Right Shift
Move the least significant bit to the most significant
Barrel Left Shift
Move the most significant bit to the least significant
Shifts using other bits to fill
Sign, Carry, Overflow, etc.
Negative Numbers
What is a negative number?
Mathematically, it’s the additive inverse
Something we add to the current number to get the additive identity value,
How do we represent this?
In decimal notation, we simply use a sign
In a computer, with a fixed number of bits, we give up one bit to hold the sign.
Most significant bit
0 is positive
1 is negative