LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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


Reply
  Search this Thread
Old 01-26-2006, 02:24 AM   #1
dreams
Member
 
Registered: Oct 2005
Location: Beijing, China
Distribution: ubuntu 7.04, Mandriva 2007.0
Posts: 39

Rep: Reputation: 15
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
 
Old 01-26-2006, 03:02 AM   #2
StringCheesian
LQ Newbie
 
Registered: Nov 2005
Distribution: Gentoo
Posts: 4

Rep: Reputation: 0
hexdump
man hexdump
 
Old 01-26-2006, 03:30 AM   #3
dreams
Member
 
Registered: Oct 2005
Location: Beijing, China
Distribution: ubuntu 7.04, Mandriva 2007.0
Posts: 39

Original Poster
Rep: Reputation: 15
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
 
Old 01-26-2006, 05:49 AM   #4
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
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.
 
Old 01-26-2006, 08:35 AM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
or type "ascii" into Google and find one of a bazillion "decoder rings" published by good samaritans.
 
Old 01-26-2006, 09:11 AM   #6
berbae
Member
 
Registered: Jul 2005
Location: France
Distribution: Arch Linux
Posts: 540

Rep: Reputation: Disabled
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.
 
Old 01-26-2006, 09:36 AM   #7
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,187

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
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.
 
Old 01-26-2006, 08:34 PM   #8
dreams
Member
 
Registered: Oct 2005
Location: Beijing, China
Distribution: ubuntu 7.04, Mandriva 2007.0
Posts: 39

Original Poster
Rep: Reputation: 15
I have handled followed by your suggestions.
Thank u so much indeed everyone.
 
Old 01-27-2006, 07:43 AM   #9
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,499
Blog Entries: 2

Rep: Reputation: 68
man ascii gives to you the same.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Decimal to binary maldini1010 Programming 6 02-01-2005 04:03 PM
How to enter high-ascii chars in a Linux editor? Kropotkin Linux - Newbie 4 11-27-2004 10:28 AM
Linux Username and password only ASCII? LogicMagic Linux - Newbie 5 02-26-2004 03:30 PM
ASCII Codes in linux slackmagic Linux - Newbie 2 12-22-2003 09:25 AM
Printing a linux ASCII file in windows ChimpFace9000 Linux - General 2 05-05-2002 06:00 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:49 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration