Carramba said:
thanx matte!
It was exactly what I mean, and Iam sorry for my bad english....
I have just one more question about you code,
is it general solution to divide 8 bits into 2groups of four, by
'hiding' first four bits and then shifting to right. or I have
missunderstod?
When shifting a byte to the right, it is not necessary to "hide" (the
term is "masking") the upper bits if it's only a byte your interested in
(e.g. a number in the range from 0 to 255). But it doesn't hurt, it is
definitely required if you need to access bits within a "word" that is
two bytes long.
lastFourBites=biteVariabel>>4;
76543210
hhhhllll <- Before the shift
0000hhhh <- After the shift
firsFourBites=biteVariabel & 0xF;
76543210
hhhhllll <- Before the mask
0000llll <- After the mask
By the way, the name for a group of four bits is called a "nibble".
You should be able to find good resources on "bit manipulation" and "bit
operators" such as "and", "or", "xor" (or "eor").
In C:
bitwise and is &
bitwise or is |
bitwise xor is ^
bitwise not is ~
Note, this give different results for
logical and is &&
logical or is ||
logical not is !