- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Convert Hex to Binary in HP UX
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
Discussions
Discussions
Discussions
Forums
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
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-15-2011 02:38 AM
тАО02-15-2011 02:38 AM
Convert Hex to Binary in HP UX
Hi,
In bash I can do:
$ echo -e -n "\xab\xcd\xef"|od -A n -tx1
ab cd ef
$ printf "%b" "\xab\xcd\xef"|od -A n -tx1
ab cd ef
but ksh only admits "\0", not "\x". How can I do this in ksh?
Thanks in advance,
Jose Luis
- Tags:
- hex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-15-2011 04:03 AM
тАО02-15-2011 04:03 AM
Re: Convert Hex to Binary in HP UX
Try with binary calculator command:
#echo "ibase=16;obase=2;3E8"|bc
Check binary calculator command syntax:
#man bc
Rgds.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-15-2011 05:18 AM
тАО02-15-2011 05:18 AM
Re: Convert Hex to Binary in HP UX
#!/bin/ksh
#set -x
# Written: Rita Workman
#
echo "Convert DECIMAL / HEX utility:"
echo ""
echo " Enter a 1 to convert dec-to-hex "
echo " Enter a 2 to convert hex-to-dec"
echo " Enter an E to exit"
read e_code
case "$e_code" in
*Ee|Qq|quit|exit|bye) echo Quitting! See you Later; exit ;;
2)
echo "Converting hexidecimal to decimal...:"
echo ">>> Enter decimal value: "
read HEX
echo $HEX
DECV=`echo "0X$HEX=D" | /usr/bin/adb -o`
echo "DECIMAL value is: $DECV"
echo ""
;;
1)
echo "Converting decimal to hexidecimal.."
echo ">>> Enter decimal value: "
read DECV_in
echo $DECV_in
DECV=`echo "0D$DECV_in=X" | /usr/bin/adb -o`
echo "HEX value is: $DECV"
echo ""
;;
esac
Rgrds,
Rita
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-15-2011 06:12 AM
тАО02-15-2011 06:12 AM
Re: Convert Hex to Binary in HP UX
The bash shell differs slightly from either the 'ksh' or POSIX shell of HP-UX ('/usr/bin/sh').
That said, if you want to convert hexadecimal to binary you could do:
# perl -e 'printf qq(%#b\n), hex(shift)'
Pass the value you want converted, like:
# perl -e 'printf qq(%#b\n), hex(shift)' abcdef
0b101010111100110111101111
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-15-2011 06:46 AM
тАО02-15-2011 06:46 AM
Re: Convert Hex to Binary in HP UX
I have found this solutions on Internet:
echo -n "abcdef"|perl -e 'print pack "H*", $_ for <>; '|od -A n -tx1
Regards,
Jose Luis
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-15-2011 03:38 PM
тАО02-15-2011 03:38 PM
Re: Convert Hex to Binary in HP UX
bring up xhpcalc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-17-2011 12:37 AM
тАО02-17-2011 12:37 AM
Re: Convert Hex to Binary in HP UX
$ typeset -i2 x=16#deadbeef; echo $x
2#11011110101011011011111011101111
ksh allows larger, unfortunately not unsigned:
$ typeset -i2 x=16#deadbeeffeedface; echo $x
-2#10000101010010010000010001000000000001000100100000010100110010
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-17-2011 05:36 AM
тАО02-17-2011 05:36 AM
Re: Convert Hex to Binary in HP UX
> I have found this solutions on Internet:
> echo -n "abcdef"|perl -e 'print pack "H*", $_ for <>; '|od -A n -tx1
Your question was misleading. I would have framed it as how to convert a string into hexadecimal nybbles (4-bit groups of hexadecimal characters).
That said, this is shorter and more generalized:
# echo "abcdef"|perl -ne 'chomp;print pack "H*",$_'|od -A n -tx1
Regards!
...JRF...