need script to convert number in hexadecimal


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting need script to convert number in hexadecimal
# 1  
Old 04-20-2004
need script to convert number in hexadecimal

hi ,
i need a script to convert number into hexadecimal base
for example: 237=>ED
it s very important for me thank you in advance for you help
# 2  
Old 04-20-2004
see man od
# 3  
Old 04-20-2004
echo 'obase=16;237'| bc
is one solution. ksh has built-in support for base arithmetic. It's not as conveinent, but it is very fast for scripting.
i=237
typeset -i16 i
echo $i
# 4  
Old 11-07-2008
decimal to hexadecimal coversion continued

Hi,

I would like to build on this example. How would I take the value from that hexadecimal conversion and store it in a variable. For example, I have a script that does the following:

echo "Please enter how many cycles you would like to run :\c"
read cycles
let input=$cycles/8
echo $input

I would like to convert "$input" to a hexadecimal value, then store it in a new variable so I can use the hex converted value in my program. Any pointers on how to do that? Thanks in advance
# 5  
Old 11-08-2008
Code:
printf "%x" $input | read newvariable
# or
newvariable=$(printf "%x" $input)

newvariable contains the hex value of the input variable.
# 6  
Old 11-08-2008
It worked!

Thanks Jim,

much appreciated
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Convert hexadecimal value to decimal value

Hi All, cat filename | awk '{print $1, $2, $4, $5, $6, $7, $8, $9, $10;}' | awk 'NF > 0' OUTPUT: 2015-01-19 00:12:32 00000000fbfa0000 000000009ae5cf80 014d 015d 0017 003c 0362de20 2015-01-19 00:13:52 00000000fc820000 00000000994c6758 014c 015d 000b 003c 08670250 2015-01-19 00:14:25... (12 Replies)
Discussion started by: sam@sam
12 Replies

2. Shell Programming and Scripting

Need a script for automation the convert a lot number audio files to another format

I have a lot number audio files in the MP3 proprietary format, I want to convert them to 'opus' the free and higher quality format, with keep metadata also. My selection command-line programs are SoX (Sound eXchange) for convert MP3 files to 'AIFF' format in order to keep quality and metadata*... (1 Reply)
Discussion started by: temp-usr
1 Replies

3. Shell Programming and Scripting

Convert UNIX rights in a number in a sh script

Hello, i'm trying to write a script sh to convert the rights of a folder or file in a number. Explain: ls -l = rwxrwxrwx so i must display 777. Do you known where i can find so convert script Thanks Use code tags, thanks. (11 Replies)
Discussion started by: steiner
11 Replies

4. Shell Programming and Scripting

Convert hexadecimal value in decimal value

hi all, this is my script: #! /bin/sh minutes=$( { i2cget -f -y 0 0x51 3; } 2>&1 ) minutes=${minutes:2} hour=$( { i2cget -f -y 0 0x51 4; } 2>&1 ) hour=${hour:2} day=$( { i2cget -f -y 0 0x51 5; } 2>&1 ) day=${day:2} month=$( { i2cget -f -y 0 0x51 7; } 2>&1 ) month=${month:2} ... (6 Replies)
Discussion started by: enaud
6 Replies

5. Shell Programming and Scripting

To convert file with decimal to another file with Hexadecimal

I have a text file of alphanumeric values listed one by one. I have to convert them to hexadecimal equivalents for each character seperated by ":" in Unix bash shell script. For example, 12345678 has to be converted to 31:32:33:34:35:36:37:38 (10 Replies)
Discussion started by: mathie
10 Replies

6. Shell Programming and Scripting

Test Hexadecimal number

Hi, I would like test if a number (with 2 digit, for example a9 , 0b ) is a hexadecimal number with 2 digit ? (2 Replies)
Discussion started by: francis_tom
2 Replies

7. Shell Programming and Scripting

printing format for hexadecimal signed number

Hello Experts,, I m facing a problem as follows.. need help.. When I am giving the below command it gives me three digit hexadecimal number , for ex :- printf("%0.3x", 10); Output: 00a But I want the same for signed number also. Now when I am specifiying the... (10 Replies)
Discussion started by: user_prady
10 Replies

8. Shell Programming and Scripting

C Shell Script to convert a number into minutes

Could anyone tell me how to write a C shell script according to the following requirement. Write a C shell script convertmin which will read in a number, thought of as representing minutes, and print out the number of hours/minutes it represents so: Note: you are required to check exception... (1 Reply)
Discussion started by: Ringo
1 Replies

9. UNIX for Dummies Questions & Answers

Convert hexadecimal to decimal base

Hello ! Does anyone knows how can I convert hexadecimal to decimal base in the ksh or csh script ?? Thanks ! Witt (1 Reply)
Discussion started by: witt
1 Replies

10. UNIX for Dummies Questions & Answers

script for nums in Hexadecimal base

Hi: I´ve developed a script that count in decimal base. this is a example: ini=0 end=0 ini=$1 end=`expr $2+1` i=$ini while do .. .. i=`expr $i+1` done Could you say me how dou you count in hexadecimal base? Thanks (1 Reply)
Discussion started by: AlvaroD
1 Replies
Login or Register to Ask a Question