Help: C char bits operations to python converting

gangli at msn.com gangli at msn.com
Wed Sep 27 16:33:17 CEST 2000


In article <8qst1l$rbj$1 at nnrp1.deja.com>,
  fredrik at pythonware.com wrote:
> 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
>
> it sure does.  try again.
>

It does not:
>>> (ord('N') - ord('A')) << 4
208


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list