Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
01-26-2006, 02:24 AM
|
#1
|
|
Member
Registered: Oct 2005
Location: Beijing, China
Distribution: ubuntu 7.04, Mandriva 2007.0
Posts: 39
Rep:
|
How to get ascii value (decimal ) of chars in linux?
How to get ascii value (decimal ) of chars in linux ?
e.g.
ascii a
-> result: 97
Is there any command like that?
thank u so much
|
|
|
|
01-26-2006, 03:02 AM
|
#2
|
|
LQ Newbie
Registered: Nov 2005
Distribution: Gentoo
Posts: 4
Rep:
|
hexdump
man hexdump
|
|
|
|
01-26-2006, 03:30 AM
|
#3
|
|
Member
Registered: Oct 2005
Location: Beijing, China
Distribution: ubuntu 7.04, Mandriva 2007.0
Posts: 39
Original Poster
Rep:
|
hello StringCheesian
hexdump 's parameter must be a file
It couldn't be a char
what i want to get is , input a char followed by a command , and the output is the ascii value 
|
|
|
|
01-26-2006, 05:49 AM
|
#4
|
|
Senior Member
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515
Rep:
|
Have you tried looking at "printf"?
If you know it from C, it is pretty much the same.
"printf" allows you to print the value of a shell variable, in different formats.
Try printing the char as an integer (%d), octal or hex number.
Most shells have "printf" as a built-in command.
|
|
|
|
01-26-2006, 08:35 AM
|
#5
|
|
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,797
|
or type "ascii" into Google and find one of a bazillion "decoder rings" published by good samaritans.
|
|
|
|
01-26-2006, 09:11 AM
|
#6
|
|
Member
Registered: Jul 2005
Location: France
Distribution: Arch Linux
Posts: 530
Rep:
|
Hello dreams
You may try:
echo 'a'|od -N 1 -i
which gives:
0000000 97
0000001
Or to get only the value:
echo 'a'|od -N 1 -i|head -1|tr -s " "|cut -d " " -f 2
Is this usable by you?
Last edited by berbae; 01-26-2006 at 09:23 AM.
|
|
|
|
01-26-2006, 09:36 AM
|
#7
|
|
Senior Member
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 3,938
|
Quote:
|
Originally Posted by dreams
hello StringCheesian
hexdump 's parameter must be a file
It couldn't be a char
what i want to get is , input a char followed by a command , and the output is the ascii value 
|
Not quite true: It can be stdin from a pipe:
Code:
$ echo -n a | hexdump -d
0000000 00097
0000001
or, if you just want the decmil value:
Code:
$ echo -n a | hexdump -d | gawk '{print $2}'
00097
Edit:
Or, if you want an ascii command:
Code:
$ cat ascii
#! /bin/bash
echo `echo -n $1 | hexdump -d | gawk '{print $2}'`
$ ./ascii a
00097
Last edited by PTrenholme; 01-26-2006 at 09:48 AM.
|
|
|
|
01-26-2006, 08:34 PM
|
#8
|
|
Member
Registered: Oct 2005
Location: Beijing, China
Distribution: ubuntu 7.04, Mandriva 2007.0
Posts: 39
Original Poster
Rep:
|
I have handled followed by your suggestions.
Thank u so much indeed everyone. 
|
|
|
|
01-27-2006, 07:43 AM
|
#9
|
|
Senior Member
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,392
Rep:
|
man ascii gives to you the same.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 06:54 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|