hex data conversion


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users hex data conversion
# 1  
Old 03-01-2006
hex data conversion

Dear friends,

I have hexadecimal data like this.

now i want to read each letter and convert to decimal format.

for example.:

from the below data first i have to read hex data 0 and convert to 4 bit decimal value ie 0000.

similarly second letter 8 decimal value is 1000.

like this.

each decimal value i have to store in one variable.


data:

085F40 00401C 09581B 0112D4 034AB6 0581D9 04AF17 068AB5 00D962 0C9140 000000 000000 000000


is there any unix function directly convert this Hex data to decimal data.


please help me.


thanks in advance.
# 2  
Old 03-02-2006
Do you mean binary? Hex 8 is 1000 in binary not decimal. Anyway, use bc for base conversions, e.g...
Code:
$ echo 'ibase=16; obase=2; 8'|bc
1000

# 3  
Old 03-02-2006
Quote:
Originally Posted by Ygor
Do you mean binary? Hex 8 is 1000 in binary not decimal. Anyway, use bc for base conversions, e.g...
Code:
$ echo 'ibase=16; obase=2; 8'|bc
1000

yes thank u ygor.

your script is working fine.

but the problem is if i give hex numbers from 0 to 7 the output is not 4 bit binary.

for example:

if i give
echo 'ibase=16; obase=2; 2' | bc
10

but actually i want 4 bit binary number .

like this.

if i give 2 then it should be 0010 not 01

how it is possible.

please help.

regards
rajan
# 4  
Old 03-02-2006
Perhaps look at the man pages for printf.
# 5  
Old 03-02-2006
suppose you are reading the binary value in a variable s odo it like this

Quote:
typeset -Z4 b_var
b_var=`echo 'ibase=16; obase=2; 2' | bc`
Gaurav
# 6  
Old 03-02-2006
Note that typeset -Z is only available in ksh.
# 7  
Old 03-02-2006
is typeset -z will work in csh or not

if it works please give me syntax.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How add 0 in hex conversion?

Hi, Got the below code in this forum, for i in `cat test`; do printf "%16s\n" $(echo "ibase=10;obase=16;$i" | bc) done Understand, this will not give output with '0'. Need help to get the output with '0'. Regards, Siva (2 Replies)
Discussion started by: ksgnathan
2 Replies

2. Shell Programming and Scripting

String to HEX conversion in UNIX

i have this below string which i need to convert it to HEX. i have already tried it but it showing extra few things on it.. let me show what i have done and what is the output i am getting and what is the desired output the input string is "!\"\"\"\"\"\"\"!\"\"\"\"\"\"\"" which is... (4 Replies)
Discussion started by: vivek d r
4 Replies

3. Shell Programming and Scripting

HEX to DEC Conversion

I'm trying to convert hex to dec and with the help of output i need to do the process. If i execute the below code assetValue=8f assetNavigation=$(echo "ibase=16; "$assetValue"" | bc) echo $assetNavigation i'm getting the error below $ sh script.sh (standard_in) 1: syntax error... (2 Replies)
Discussion started by: Amutha
2 Replies

4. Shell Programming and Scripting

HEX to DEC Conversion Error

I'm trying to convert hex to dec and with the help of output i need to do the process. If i execute the below code assetValue=8f assetNavigation=$(echo "ibase=16; "$assetValue"" | bc) echo $assetNavigation i'm getting the error below $ sh script.sh (standard_in) 1: syntax error... (1 Reply)
Discussion started by: Amutha
1 Replies

5. Programming

Hex string conversion?

Hello all. I need help... How can I cenvert this 42ec93df826c804ea531c56594db453d54daad4b to normal text? What convertor I have to use? Thanks. (12 Replies)
Discussion started by: escudo
12 Replies

6. Shell Programming and Scripting

Decimal to hex conversion

Dear All PROs Thanks in advance need a shell for Decimal to hex conversion input file (decimal values) 65,5,48,66,133,131,118,47 65,5,48,66,133,131,83,63 . . desire output should be (Hex value)... (11 Replies)
Discussion started by: The_Archer
11 Replies

7. Shell Programming and Scripting

Reading hex data from assembler

Hi, I have files that has got ebcdic character set and also, there are fields like binary and hex fields. is there a way to convert this to normal ascii data by taking care of comp & comp-3 fields? Many Thanks!! (10 Replies)
Discussion started by: ahmedwaseem2000
10 Replies

8. UNIX for Dummies Questions & Answers

Conversion from EBCDIC to HEX

Hello, Is there any utility around able to deal with the conversion of some EBCDIC coded string into an hexadecimal value? Thanks (1 Reply)
Discussion started by: Indalecio
1 Replies

9. UNIX for Dummies Questions & Answers

ANSI C, char to hex conversion

Hi, I have a char buf,ch; and the buf is filled with the result from MySQL server which I get like this numbytes = recv(sock, buf, 1024, 0));I have the followingcode to display the results printf("received %ld bytes:\n",numbytes); for(c=0;c<numbytes;c++){ ch = (char)buf; ... (2 Replies)
Discussion started by: alikims
2 Replies

10. Shell Programming and Scripting

Hex Conversion

I need to have my scripts import volume groups and mknod devices files. I have most of the script working but the device file needs to be in the format 0x??0000 (where the question marks are my HEX representations of the volume group number. I have the code below and the output it produces which... (2 Replies)
Discussion started by: insania
2 Replies
Login or Register to Ask a Question