Reputation: 430
Just a little question about math..
I have a WORD with that value 25467. I want to get two bytes (lo / hi) from that, that is 123 and 99. There's a way to calculate that two bytes only with a calculator, avoid bitmask (&&) or shifting (<< >>).
Something like (25467 / x) - y = hi word (25467 / x) * z = lo word?
Upvotes: 2
Views: 348
Reputation: 83
Assume that the WORD is organized in the order: HIBYTE LOWBYTE, then hi = (WORD)/256; low = WORD % 256
Upvotes: 0
Reputation: 4628
Shifting is equivalent with dividing with 2. So it you'd shift by 8 bit, that's dividing by 2^8:
wordValue = 25467;
hi = wordValue / 256;
low = wordValue - hi * 256
Upvotes: 0