473,395 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to covert ASCII to integer in Python?

Is there any built in function that converts ASCII to integer or vice versa
in Python?

Thanks!
Feb 22 '07 #1
10 53338
John wrote:
Is there any built in function that converts ASCII to integer or vice versa
in Python?

Thanks!

You probably should go through the tutorial ASAP that is located here:

http://docs.python.org/tut/
Convert ascii string to integer:

a='1'
b=int(a)

Convert integer to ascii string:

a=1
b=str(a)

or

a=1
b="%i" % a

-Larry Bates

Feb 22 '07 #2
On Feb 22, 5:43 pm, "John" <rds1...@sh163.netwrote:
Is there any built in function that converts ASCII to integer or vice versa
in Python?

Thanks!
Try int.
ie.

try:
int_val = int(str_val)
except ValueError:
# conversion failed

Keir.

--
Keir Robinson
Sometimes a scream is better than a thesis. (Emerson)
Feb 22 '07 #3
hg
John wrote:
Is there any built in function that converts ASCII to integer or vice
versa in Python?

Thanks!
>>int('10')
10
>>str(10)
'10'
>>>
Feb 22 '07 #4
I just found ord(c), which convert ascii to integer.

Anybody know what the reverse is?

"John" <rd*****@sh163.netwrote in message
news:er***********@netnews.upenn.edu...
Is there any built in function that converts ASCII to integer or vice
versa
in Python?

Thanks!


Feb 22 '07 #5
John wrote:
I just found ord(c), which convert ascii to integer.

Anybody know what the reverse is?

"John" <rd*****@sh163.netwrote in message
news:er***********@netnews.upenn.edu...
>Is there any built in function that converts ASCII to integer or vice
versa
>in Python?

Thanks!


The phrasing of your question threw us all. What you want is chr

backslash=chr(92)

-Larry Bates
Feb 22 '07 #6
"John" <rd*****@sh163.netwrites:
I just found ord(c), which convert ascii to integer.
Anybody know what the reverse is?
chr(i)
Feb 22 '07 #7
"John" <rd*****@sh163.netwrites:
I just found ord(c), which convert ascii to integer.

Anybody know what the reverse is?
The inverse of "ord" is "chr":

% python
Python 2.5 (r25:51908, Jan 5 2007, 00:12:45)
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>ord('i')
105
>>chr(105)
'i'
>>>
IIRC, the first use of the names "ord" and "chr" for these functions
appeared in the Basic language in the 1960's ... in case anyone is
interested in this bit of historical trivia.
--
Lloyd Zusman
lj*@asfast.com
God bless you.

Feb 22 '07 #8
On Feb 22, 6:35 pm, Lloyd Zusman <l...@asfast.comwrote:
"John" <rds1...@sh163.netwrites:
I just found ord(c), which convert ascii to integer.
Anybody know what the reverse is?

The inverse of "ord" is "chr":

% python
Python 2.5 (r25:51908, Jan 5 2007, 00:12:45)
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>ord('i')
105
>>chr(105)
'i'
>>>

IIRC, the first use of the names "ord" and "chr" for these functions
appeared in the Basic language in the 1960's ... in case anyone is
interested in this bit of historical trivia.
In the versions of Basic that I've seen they were ASC (clearly ASCII)
and CHR$. I first saw ord in Pascal.

Feb 22 '07 #9
On Feb 23, 5:23 am, "John" <rds1...@sh163.netwrote:
I just found ord(c), which convert ascii to integer.
ord('\xff') -255
ord(unichr(666)) -666

What ascii?

What is stopping you from reading the documentation section on built-
in functions (http://docs.python.org/lib/built-in-funcs.html)?

That way, you might find an answer to whatever your question really
is, without wasting time (yours and that of others trying to guess).
>
Anybody know what the reverse is?

"John" <rds1...@sh163.netwrote in message

news:er***********@netnews.upenn.edu...
Is there any built in function that converts ASCII to integer or vice
versa
in Python?
Thanks!

Feb 23 '07 #10
hg

<yours and that of others trying to guess>

Some people spend many buck bying guessing games ... be nice !

hg

Feb 23 '07 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: lucas | last post by:
hello one and all, i am very new to java and i need to take an ascii character, say "A" or "a" and convert it into its ascii integer code, say 65 or 97 respectively. then i need to also go in...
4
by: Mark Dickinson | last post by:
Here's a variant of André's brilliant idea that's 119 characters long, and fully printable: j=''.join;seven_seg=lambda z:j(j(' _ | |_ _|_|' )%u*2:]for a in z) +"\n"for u in(3,7,8)) Mark
6
by: Calros Lo | last post by:
Dear all: I develop a programe that need when I get a string , such as "123" or "ABC",if I get string "123" and the system will help me to create new string "124" , if I get string "ABC" and the...
4
by: micahc | last post by:
I currently have a Python program that reads in emails from a POP3 server. As soon as the message is read in it is fed directly into a PostgreSQL database for storage. Later, it is broken down...
1
by: ronrsr | last post by:
I have an MySQL database called zingers. The structure is: zid - integer, key, autoincrement keyword - varchar citation - text quotation - text I am having trouble storing text, as typed in...
13
by: Mantorok | last post by:
Hi Is it possible to convert 2 char values to an integer and be able to reverse it? I'm sure there must be some algorithm to achive this. Any ideas? Thanks Kev
12
by: Steve Howell | last post by:
The never-ending debate about PEP 3131 got me thinking about natural languages with respect to Python, and I have a bunch of mostly simple observations (some factual, some anecdotal). I present...
4
by: Skonieczny, Chris | last post by:
YOU SHOULD REMOVE or CORRECT YOUR POST here: http://mail.python.org/pipermail/python-list/2007-February/427841.html It is not true - eg. try : a='P' # P is ASCII , isn't it ? ...
2
by: Joshua Kugler | last post by:
Skonieczny, Chris wrote: int() converts a strings that is a valid intenter. What you're looking for is ord(). In : ord('d') Out: 100 In : a='P'
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.