Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Re: Hexadecimal...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 7 of 11 Topic 9522 of 9828
Post > Topic >>

Re: Hexadecimal and bitwise operations

by "Ivan Vecerina" <_INVALID_use_webform_@[EMAIL PROTECTED] > Apr 19, 2008 at 06:17 PM

{ edits: double-spacing removed manually. -mod }

<Hakusa@[EMAIL PROTECTED]
> wrote in message
news:a3532269-02f3-4f97-afa9-cf9a9303f9bd@[EMAIL PROTECTED]
 Maybe this is just my lack of experience with working with hex, but...
:
: 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.
Indeed, the operation happens bit-wise.

: Obviously, that's not helpful. How can I take my hex numbers and do
: the & operation? Or maybe my question is wrong--how can I access the
: n'th digit?
You access the n'th digit by using a mask where all bits corresponding
with the hex digit are set.
Assuming that you expect  a=0x25E1  and  b=0x0010  to result in
r=0x00E0,
one approach would be to write:
   r = a & (b*0xF)
If you want to extract the digit as a value in 0..0xF:
   r = (a/b)&0xF;   // -> 0xE;

In some cases, using the bit-****ft operators << and >> may be
useful too.

: NOTE: This thread was created after about an hour or more of research.
: Simply pointing me in the right direction would be appreciated.

I hope this is enough to inspire you... -Ivan
-- 
http://ivan.vecerina.com/contact/?subject=NG_POST
<- email contact form
Brainbench MVP for C++ <> http://www.brainbench.com


      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 11 Posts in Topic:
Hexadecimal and bitwise operations
"Hakusa@[EMAIL PROTE  2008-04-19 02:01:53 
Re: Hexadecimal and bitwise operations
Alberto Ganesh Barbati &l  2008-04-19 18:09:27 
Re: Hexadecimal and bitwise operations
Pavel Minaev <int19h@[  2008-04-19 18:13:49 
Re: Hexadecimal and bitwise operations
=?UTF-8?B?QmrDtnJu?= Hend  2008-04-19 18:14:09 
Re: Hexadecimal and bitwise operations
Goedson Paixao <goedso  2008-04-19 18:14:55 
Re: Hexadecimal and bitwise operations
Brendan <catphive@[EMA  2008-04-19 18:13:28 
Re: Hexadecimal and bitwise operations
"Ivan Vecerina"  2008-04-19 18:17:19 
Re: Hexadecimal and bitwise operations
Michael.Boehnisch@[EMAIL   2008-04-19 18:15:12 
Re: Hexadecimal and bitwise operations
"Hakusa@[EMAIL PROTE  2008-04-20 16:13:16 
Re: Hexadecimal and bitwise operations
MiB <Michael.Boehnisch  2008-04-20 21:02:20 
Re: Hexadecimal and bitwise operations
Jonathan Thornburg <cl  2008-04-25 03:46:08 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 15:44:38 CDT 2008.