473,608 Members | 2,263 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

String to ASCII values

Hello,

How do I convert a string like 'A' to its ASCII value(s) ?

Greets,
Benjamin
Jul 18 '05 #1
3 47789
Benjamin Hepp wrote:
Hello,

How do I convert a string like 'A' to its ASCII value(s) ?

Greets,
Benjamin


ord('A')

hth,
anton.

Jul 18 '05 #2
Benjamin Hepp wrote:
Hello,

How do I convert a string like 'A' to its ASCII value(s) ?


Perhaps you want something like this:
for x in 'abcde':

... print ord(x), hex(ord(x))
...
97 0x61
98 0x62
99 0x63
100 0x64
101 0x65

Look here for documentation:

http://www.python.org/doc/current/li...-in-funcs.html
Dave

--
Dave Kuhlman
http://www.rexx.com/~dkuhlman
dk******@rexx.c om
Jul 18 '05 #3
Benjamin Hepp wrote:
Hello,

How do I convert a string like 'A' to its ASCII value(s) ?


The struct module is nifty, and most likely faster than ord()
#########

from struct import unpack

def toBytes(value):
"Turns a string into a list of byte values"
return unpack('%sB' % len(value), value)

print toBytes('ABCDEF G')

regards Max M

Jul 18 '05 #4

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

Similar topics

4
7409
by: Neil W. | last post by:
I'm coming back to Perl after a long absence. I am trying to add up the ascii values of the characters in a string. Can anyone refresh my memory? Thanks.
6
6816
by: Drew | last post by:
I need to display the ASCII numeric values of each letter in a string. I think strings are stored in unicode in C# (?) I can convert the string to a char array but how do I get the ascii values of each character? Thanks, Drew
1
2992
by: Kermit Piper | last post by:
Hello, I have a function that lets me convert one character and throw an alert with the corresponding ASCII value, but what I am having trouble with is applying it to a text box. What I'm trying to do is when characters are entered the function will loop through the entered values and throw an alert for each of the corresponding ASCII values for each of the characters entered. I am trying to alert the user for every character that is...
1
4224
by: Kermit Piper | last post by:
Hello, OK, almost there. Here's what I have so far, which handles characters as they're typed in. Could someone please show me how I would loop through all the values that are entered if a block of text was pasted in, and then grab the ascii value(s) that are > 128?: <script type="text/javascript"> function toASCII(s) {
7
4025
by: Jeffrey Spoon | last post by:
Hello, I'm a bit stuck trying to convert a text file which contains extended ASCII text and changing the ASCII values so they become readable. I do this by subtracting 127 from the ASCII value. However, at the moment I am just getting more gibberish so I'm probably doing something wrong. I tried using ASCII Encoding before to get the ASCII values. Although this worked for 0-127 ASCII values, extended ASCII gave strange values (such as 1992...
1
4167
by: adnanahmed714 | last post by:
hi all i have a string <cr><lf>999,1.52,32.85,5.91,15.81,1.39,26.17,15.75,12.3 want to calculate its ASCII values sum which is equal to 2411.How can i calculate ascii sum of all the string values. thanks in advance
0
3160
by: nmsreddi | last post by:
Hi friends I am working on serialport in c# ,i am using C#2005 i have successfully done the serial communication with GSM modem and able to send and receive data , the main problem ,the serial port class in C# is accepting only ASCII values upto 127 only, the values those greater than 127 ,is automatically converted to value 63(?) ,ihave searched alot in the net and finally found from MSDN that ,serialport class accepts only ASCII values...
10
6057
by: manontheedge | last post by:
I want to read in an image file ( bmp, jpeg, ... ) so I can retain it's ascii / binary values, and alter the image. How can I do this in C++ ( I'm using Visual Studio, various versions ). so basically, I want to make a big matrix of values in an array. I know this can be done using a hex editor, but in C++ I'm not sure how to get the ascii values. Any help is appreciated.
0
1372
by: squrel | last post by:
Hello All, I have a table in my database with a field itemqty and the type was int and need to change it to decimal as i need the decimal point in my textbox.. i have a code for integer ascii values as bellow i want to change this code and whtever i m doing my values is coming wrong coz i want both integer as well as decimal point ascii values. can anyone help me in my code. thank u in advance Private Sub...
5
4645
by: siddhanta | last post by:
hi, i read the ascii value from a file and wrote the decimal one in other file. But values above "127" i.e. extended ascii are printed as" 65533." here ais wat i did: private void button1_Click(object sender, EventArgs e) { int b = new int; StreamReader sw = new StreamReader("c: \\28D.09N"); for (int i = 0; i < 5000; i++) {
0
8063
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8475
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8338
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6816
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6013
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3962
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4024
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2474
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1594
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.