|
-
Sep 23rd, 2009, 06:08 PM
#32
Re: Bits, Bytes and Boomerangs (without the boomerangs...)
 Originally Posted by chris128
So one thing I am still a bit puzzled about (it may just be the terminology) is bit shifting. If I can test for any individual bit being set by just using AND then why/when would I use bit shifting? Is that more for when you want to set a bit rather than just checking to see if a bit is set?
That OPCODE is 4 bits - right? That means it's a value from 0000 (0) to 1111 (15).
If you want to extract that value - and it's in the BYTE - you need to shift it down to position 0 and also MASK it to hide other bits that shift down with it.
So once again - the byte with the opcode - let's say it:
1101 0111
The 1010 bits is the 10 values I want to extract. The decimal value of 1101 0111 is not 10 [edit - oops] - so first thing is to shift it down
1101 0111 / 8
0001 1010 - now the 1010 is in bit 0, bit 1, bit 2 and bit 3
0000 1111 - this is the 15 mask
AND these and you get
0000 1010 - this is the 10 I want - it's in a byte - but the value of 10 (from the opcode) came through.
Last edited by szlamany; Sep 23rd, 2009 at 06:23 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|