[Tutor] Bit Manipulations

Praveen Pathiyil ppathiyi@cisco.com
Wed, 4 Jul 2001 13:28:17 +0530


HI,

The operation is to be done on an input obtained from the recv() call. The
other side is sending the data in binary format.
For parsing, what we do is to represent each byte by the corresponding
2-digit hex value.

i.e., 1010 0101 will be converted as a5.

It is from such a hex value that i have to find the value of the MSB. I
guess i can just check whether the first digit in the hex representation is
less than 8, right ?

Can we do direct operations on the binary input got from the recv() call ?
How will python treat such input ? I mean as which type should we take them
?

Thx,
Praveen.
----- Original Message -----
From: "Danny Yoo" <dyoo@hkn.eecs.berkeley.edu>
To: "Praveen Pathiyil" <ppathiyi@cisco.com>
Cc: <tutor@python.org>
Sent: Wednesday, July 04, 2001 12:35 PM
Subject: Re: [Tutor] Bit Manipulations


> 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.
>
>