Help: C char bits operations to python converting
Darrell Gallion
darrell at dorb.com
Wed Sep 27 11:24:30 EDT 2000
>>> (ord('N') - ord('A')) << 4
208
>>> ord('N')
78
>>> ord('A')
65
>>> 208-78
130
>>> 130 << 4
2080
>>> 2080 & 0xff
32 <<<<---- Was this what you expected ?
>>>
Note: Watch out for unsigned bit twiddling
--Darrell
----- Original Message -----
From: <gangli at msn.com>
Newsgroups: comp.lang.python
To: <python-list at python.org>
Sent: Wednesday, September 27, 2000 9:23 AM
Subject: Re: Help: C char bits operations to python converting
> In article <8qrcr7$fhe$1 at panix3.panix.com>,
> aahz at panix.com (Aahz Maruch) wrote:
> > In article <8qr6au$hr4$1 at nnrp1.deja.com>, <gangli at msn.com> wrote:
> > >
> > >How could I convert following C statments to Python?
> > > char tmp_ch, tmp_ch0, tmp_ch1;
> > > tmp_ch = 'K' - 'A'; /* -> 10 */
> > > tmp_ch0 = ('N' - 'A') << 4; /* -> -48 */
> > > tmp_ch1 = tmp_ch+ tmp_ch0; /* -> -38 */
> >
> > Use the built-in ord() function.
>
> It only help convert "tmp_ch = 'K' - 'A';", but not others
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
> --
> http://www.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list