convert char to byte representation

Larry Bates larry.bates at websafe.com
Mon Oct 10 19:01:23 EDT 2005


I've always read it written that the number that is returned by
ord(c) is the "decimal" (not hex, not octal) representation of
the ASCII/UNICODE character that is stored in memory location
pointed to by variable c.  While the result is an integer (as
it couldn't really be anything else), I believe that most
character charts list the number that ord() returns as the
"decimal representation" of that character (as they normally
also show the octal and hex values as well).

Probably an "old school" answer on my part.

-Larry Bates

Grant Edwards wrote:
> On 2005-10-10, Larry Bates <larry.bates at websafe.com> wrote:
> 
> 
>>>I am trying to xor the byte representation of every char in a string with
>>>its predecessor. But I don't know how to convert a char into its byte
>>>representation. This is to calculate the nmea checksum for gps data.
> 
> 
>>ord(c) gives you decimal representation of a character.
> 
> 
> While ord(c) is what the OP needs, it doesn't give a decimal
> represention -- which I guess would be a string like "65" for
> the ASCII characer "A".  What ord() gives you is an integer
> object with the value of the character [which the hardware
> stores in binary on all of the platforms I'm aware of].
> 



More information about the Python-list mailing list