On Apr 19, 12:01 pm, "Hak...@[EMAIL PROTECTED]
" <Hak...@[EMAIL PROTECTED]
> wrote:
> I was asked to produce an M-tree class using unsigned ints in hex to
> traverse through and find nodes. The thing I'm having trouble working
> out is, I was given (on paper) 25E1 & 0010 = 00E0, but when I tried it
> on my computer, I found C++ converting it all to binary and producing
> 0x4 & 0x3 = 100 & 011 = 0.
The information you were given is clearly wrong.
> Obviously, that's not helpful. How can I take my hex numbers and do
> the & operation?
The standard operator& behaves as expected - it is, by definition,
bitwise AND.
> Or maybe my question is wrong--how can I access the
> n'th digit?
A single hex digit exactly corresponds to a group of 4 bits.
Therefore, you can use bitwise operators to extract those, keeping in
mind that 0xF is 0b1111:
0x25E1 & 0x000F -> 0001
0x25E1 & 0x00F0 -> 00E0
0x25E1 & 0x0F00 -> 0500
0x25E1 & 0xF000 -> 2000
--
[ See http://www.gotw.ca/resources/clcm.htm
for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


|