|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
printf Hexadecimal output
Code:
printf "%X\n" "A" 41 printf "%X\n" "2" 2 Expected 32 (not 2). Is there a "printf" which will output the hexadecimal value of a numeric character? |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Code:
$ printf "%d\n" 0xA 10 Code:
$ printf "%d\n" 0x20 32 Code:
$ printf "%X\n" 10 A Code:
$ printf "%X\n" 32 20 |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
@Scrutinizer,
Methyl means the ascii code of the character "2" in hexadecimal, which should be 32. |
|
#4
|
||||
|
||||
|
Quote:
Quote:
|
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
@Franklin: Oops... Code:
$ printf "%X\n" \'A 41 $ printf "%X\n" \'2 32 |
| The Following 2 Users Say Thank You to Scrutinizer For This Useful Post: | ||
Franklin52 (12-10-2010), jim mcnamara (12-10-2010) | ||
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
Thanks Scrutinizer. It's just unbroken my script!
Just for interest I had been having a go at this post but expanding the problem to any character. http://www.unix.com/aix/150117-conve...to-binary.html Last edited by methyl; 12-10-2010 at 10:35 AM.. |
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
@Scrutinizer Where is the \'[value] syntax documented for POSIX shells? I do not think I've seen it. Or more likely I ignored it.... For example: Code:
echo $(( \'A + 1 )) fails in ksh88 on Solaris 10. This does not: Code:
> printf "%d\n" \'A 65 |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| capture the output of printf into another variable | arizah | Programming | 2 | 08-10-2010 09:22 AM |
| How to format the output using float in awk{printf} | angelarosh | Shell Programming and Scripting | 4 | 05-07-2009 08:26 AM |
| Help please...output problems with printf. | pwanda | UNIX for Advanced & Expert Users | 3 | 10-19-2008 07:30 PM |
| How do I stop printf output from going into seperate txt files | chrchcol | Shell Programming and Scripting | 12 | 07-26-2006 09:08 PM |
| fixed-width printf() output on an XmList on Solaris | trido | Programming | 0 | 11-20-2002 04:21 AM |
|
|