- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: character to numeric representation
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2008 02:10 PM
02-21-2008 02:10 PM
string or letter to decimal representation.
e.g. a = ?
1a = ?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2008 03:10 PM
02-21-2008 03:10 PM
SolutionFor a quick lookup I use (a clone from) http://www.asciitable.com/
Google: asciitable.
For scripts I use whatever the language offers. For example in perl:
$ perl -e 'print chr(65)'
and
$ perl -le 'print ord("C")'
or
$ perl -le 'printf "%c", 0x43'
Enjoy!
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2008 03:21 PM
02-21-2008 03:21 PM
Re: character to numeric representation
grep'ng for particular string which may
have string -11 or -1a , etc...
11 in -11 is used as index number in array
when that string is found. Can't use 1a
unless "a" is converted to it's decimal
representation.
So if "a" is 61 or 141, according to
/usr/share/lib/pub/ascii, then the value for
1a that I would need would be 161 or 1141.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2008 04:21 PM
02-21-2008 04:21 PM
Re: character to numeric representation
Depending on your needs, you should also find 'xd' (also known as 'od') useful. You can list a file in hexadecimal, octal, or decimal:
# xd -tax /etc/hosts
# xd -tao /etc/hosts
# xd -tad /etc/hosts
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2008 04:29 PM
02-21-2008 04:29 PM
Re: character to numeric representation
That explanaiton does nto really cut it for me.
>> may have string -11 or -1a , etc...
What is the exact range?
Can it return 1A or A1 or 1$ or 1!
uppercae or lowercase?
I get the feeling that it will only return 0..9 or a..z
In that case you can use the shell base#n conversion for base 36.
$ let x=36#a
$ echo $x
10
$ let x=36#z
$ echo $x
35
$ let x=36#3
$ echo $x
3
So if "a" is 61 or 141, according to
It is not 61 or 141 is 16#61 AND 8#141
In other words, its OCTAL value is 141
It's HEX value 61 and its decimal value is 97.
/usr/share/lib/pub/ascii, then the value for
1a that I would need would be 161 or 1141.
btw..
here is an other, 'shell only' way to convert a character to its octal value string:
x=$( printf a | od -An -to1 )
$ echo $x
and back
$ echo "\0141"
a
hex: x=$(printf a | xd -An -tx1)
decimal: x=$(printf a | xd -An -td1)
What is the _real_ problem you are trying to solve. Mayb a shell script is not the optimal way to approach this. String manipulation tends to be a lot easier within AWK or PERL or such.
Good luck!
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2008 04:53 PM
02-21-2008 04:53 PM
Re: character to numeric representation
is the oct rep of the letter "a"
# perl -le 'printf "%c", 0x61'
a
And you confirmed that dec of "a" is 97.
# perl -le 'printf "%c", 97'
a
So your dec conversion line will work just
fine to convert any characters to dec.
dec output is what I was looking for. So
for the letter "a" it is 97. "b" 98, etc..
# printf a
97
I'll just run what is found as $a in
# numval=`printf $a | xd -An -td1`
Thanks as always. Ya'll are so good.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2008 04:53 PM
02-21-2008 04:53 PM
Re: character to numeric representation
is the oct rep of the letter "a"
# perl -le 'printf "%c", 0x61'
a
And you confirmed that dec of "a" is 97.
# perl -le 'printf "%c", 97'
a
So your dec conversion line will work just
fine to convert any characters to dec.
dec output is what I was looking for. So
for the letter "a" it is 97. "b" 98, etc..
# printf a
97
I'll just run what is found as $a in
# numval=`printf $char | xd -An -td1`
Thanks as always. Ya'll are so good.