- 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
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
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
тАО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