Results 1 to 2 of 2
Hi, i need help with creating script that converts hex to dec. But without using bc calculator or other methods that could convert it in one line. I need to ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 12-04-2010 #1Just Joined!
- Join Date
- Dec 2010
- Posts
- 3
Bash script HELP - Hex to Dec
Hi, i need help with creating script that converts hex to dec. But without using bc calculator or other methods that could convert it in one line. I need to make something like this script that converts dec to hex.
Thanks!
1. #!/bin/bash
2.
3. declare -r HEX_DIGITS="0123456789ABCDEF"
4.
5. dec_value=$1
6. hex_value=""
7.
8. until [ $dec_value == 0 ]; do
9.
10. rem_value=$((dec_value % 16))
11. dec_value=$((dec_value / 16))
12.
13. hex_digit=${HEX_DIGITS:$rem_value:1}
14.
15. hex_value="${hex_digit}${hex_value}"
16.
17. done
18.
19. echo -e "${hex_value}"
- 12-05-2010 #2
Homework questions are not allowed:
http://www.linuxforums.org/forum/lin...ums-rules.html
If you have a specific conceptual question, we will be happy to help, but we won't do your homework for you.



