- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Convert Decimal to Binary & Hex, and vice versa
Categories
Company
Local Language
Forums
Discussions
- Integrity Servers
- Server Clustering
- HPE NonStop Compute
- HPE Apollo Systems
- High Performance Computing
Knowledge Base
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Knowledge Base
Forums
Discussions
- Cloud Mentoring and Education
- Software - General
- HPE OneView
- HPE Ezmeral Software platform
- HPE OpsRamp Software
Knowledge Base
Discussions
Forums
Discussions
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
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
03-01-2001 12:02 AM
03-01-2001 12:02 AM
a)Convert from Decimal to Binary, & vice versa.
b)Convert from Decimal to Hexadecimal, & vice versa.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2001 12:08 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2001 12:41 AM
03-01-2001 12:41 AM
Re: Convert Decimal to Binary & Hex, and vice versa
you could use the bc command within a script ie:
-------------------------------
#!/bin/sh
# decimal to binary
dec2bin()
{
{
echo "obase=2"
echo "$1"
echo "quit"
}|bc
}
dec=255 # example
bin=$(dec2bin $dec)
echo $bin
-----------------------------------------
#!/bin/sh
# binary to decimal
bin2dec()
{
{
echo "ibase=2"
echo "$1"
echo "quit"
}|bc
}
bin=010101 # example
dec=$(bin2dec $bin)
echo $dec
-----------------------------------
#!/bin/sh
# decimal to hex
dec2hex()
{
{
echo "obase=16"
echo "$1"
echo "quit"
}|bc
}
dec=255 # example
hex=$(dec2hex $dec)
echo $hex
--------------------------------------
#!/bin/sh
# hex to decimal
hex2dec()
{
{
echo "ibase=16"
echo "$1"
echo "quit"
}|bc
}
hex=0A # example
dec=$(hex2dec $hex)
echo $dec
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2001 01:36 AM
03-01-2001 01:36 AM
Re: Convert Decimal to Binary & Hex, and vice versa
Use the "printf" command... Yes, it exist.
$ printf "dec -> hex %d = %x\n" 32 32
$ printf "hex -> dec %x = %d\n" 0x20 0x20
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2001 11:06 PM
03-04-2001 11:06 PM