Binary number manipulation

  • Thread starter Matthew A. Berglund
  • Start date
M

Matthew A. Berglund

Hello All!

I am very new to python so I am working on some ass-umptions which may be incorrect (please forgive me).

I am working on a problem that requires me to take 2 decimal integers, each of which represents half of a word. I need to slap these things together and get out another decimal integer.
A couple of questions:
1. Is there a way to typecast a variable as a binary?
2. If 1 is no, does that mean that I need to do all the manipulation in some icky string format and then go back?

I do see the bit-wise operations available and this looks like I need to simply perform these on my integers? Can it really be that simple?

Thanks,
Matt
 
I

Irmen de Jong

Matthew said:
I am working on a problem that requires me to take 2 decimal integers, each
of which represents half of a word. I need to slap these things together
and get out another decimal integer. [...]
I do see the bit-wise operations available and this looks like I need to
simply perform these on my integers? Can it really be that simple?

Probably. Consider the following (typed at the interactive prompt):
0x1234abcd

This example assumes that both words are 16 bits.
There are some signed/unsinged issues, be warned.


--Irmen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top