The "SHR 7" (Shift Right by 7 bits?) seems to me to be selecting the first 7 bits, if so, do they then need to do an "AND $7f" action on what is now a 7-bit number? In your discussion, the number was more than 7-bits, so I can see the purpose. It seems to me that, by Kemper splitting it into the 7-bits, the "AND $7f" action becomes superfluous.
I would say that "selecting" is the wrong word here.
Lets think about shifting in decimal.
If you take a value (1E8) and SHR 3 in decimal you don't get 3 decimal digits, you get 1E5.
Thus; in base 10 shift operations divide or multiply by 10.
C
#include <bitset>
#include <iostream>
#include <cassert>
#include <cmath>
using std::bitset;
using std::cout;
int main()
{
// Therefore the following assertions can be made about shifting digits in binary (base 2)
// A
assert((1 << 1) == 2);
assert((1 << 2) == 4);
assert((1 << 3) == 8);
assert((1 << 4) == 16);
// B
assert((3 << 1) == 6);
assert((3 << 2) == 12);
assert((3 << 3) == 24);
assert((3 << 4) == 48);
// and likewise ..
// A'
assert((96 >> 4) == 6);
assert((96 >> 3) == 12);
assert((96 >> 2) == 24);
assert((96 >> 1) == 48);
// B'
assert((64 >> 5) == 2);
assert((64 >> 4) == 4);
assert((64 >> 3) == 8);
assert((64 >> 2) == 16);
// In other words, in base 2 shift operations divide or multiply by 2
// In a 14 bit number SHR 7 just happens to isolate the first 7 bits
// (value << n) == value * 2^n
// With: ((3 << 4) == 48)
const auto value = 3;
const auto n = 4;
assert((value << n) == (value * pow(2,n)));
return 0;
}
Display More