[Tutor] Bit Manipulations

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Wed, 4 Jul 2001 00:05:22 -0700 (PDT)


On Wed, 4 Jul 2001, Praveen Pathiyil wrote:

> Actually i was a bit lazy. I checked out the bitwise operators. But
> the problem for me is that the input is a hex value. So do i have to
> convert that into an integer before i apply the bitwise operators ?

How is the program inputting the numbers in?  Python will automatically
represent the numbers appropriately as 32-bit integers if we enter
hexidecimal like this:

###
>>> 0x8
8
>>> 0x9
9
>>> 0xa 
10
>>> 0xb
11
>>> 0xc
12
>>> 0xd
13
>>> 0xe
14
>>> 0xf
15
>>> 0x10
16
###

However, if we're getting the input as strings, then yes, we'll need to
convert them with the int() function.