converting hex to dec


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting converting hex to dec
# 1  
Old 02-26-2008
converting hex to dec

Hi Experts,

I have a file called "hex" which contains info like below
Quote:
0x0DD
0x1E9
0x1EA
0x1EB
0x1F4
0x1F7
0x1F9
0x1FE
0x202
0x203
0x208
0x209
0x20E
0x20F
0x210
How do i convert everything in this file to decimal value? Please advice. Thanks
# 2  
Old 02-26-2008
One solution:

Code:
cat hex | while read value
do
 printf "%d\n" $value
done

Regards
# 3  
Old 02-26-2008
Hi Franklin,

This is what i get

Quote:
root@ckpgpay11core> cat hex| while read value; do printf "%d\n" $value; done
bash: printf: 0x0DD: illegal number
bash: printf: 0x0DE: illegal number
bash: printf: 0x0E1: illegal number
bash: printf: 0x0E2: illegal number
bash: printf: 0x0E3: illegal number
bash: printf: 0x0E4: illegal number
bash: printf: 0x0E5: illegal number
bash: printf: 0x0E6: illegal number
bash: printf: 0x0E7: illegal number
bash: printf: 0x0E8: illegal number
bash: printf: 0x0F2: illegal number
bash: printf: 0x1A4: illegal number
bash: printf: 0x1B8: illegal number
bash: printf: 0x1B9: illegal number
bash: printf: 0x1BA: illegal number
bash: printf: 0x1BB: illegal number
# 4  
Old 02-26-2008
even after removing the "0x"

Quote:
root@ckpgpay11core> cat sara2 | while read value; do printf "%d\n" $value; done
bash: printf: 0DD: illegal number
bash: printf: 0DE: illegal number
bash: printf: 0E1: illegal number
bash: printf: 0E2: illegal number
bash: printf: 0E3: illegal number
bash: printf: 0E4: illegal number
bash: printf: 0E5: illegal number
bash: printf: 0E6: illegal number
bash: printf: 0E7: illegal number
bash: printf: 0E8: illegal number
bash: printf: 0F2: illegal number
bash: printf: 1A4: illegal number
# 5  
Old 02-26-2008
Hi,

Use typeset command in UNIX to do the conversion. I think you need to used typeset -i. Try typeset after removing '0x'.

Regards,
Chella
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to convert dec to hex in python?

When I try to convert big numbers I get extra numbers at the end that doesn't move plus an L character too. How to remove the 4 extra characters at the end 000L? 8b8dbbc584d9c000L 8b8dc4ddd34c6000L 8b8dcdf621bf0000L 8b8dd70e7031a000L 8b8de026bea44000L #!/usr/bin/python ... (9 Replies)
Discussion started by: bigvito19
9 Replies

2. Shell Programming and Scripting

Converting decimal to hex

How to convert decimal value to hex and than take 1st digits as variable sample data 84844294,5,6 51291736,2,3 84844294,5,6 51291736,2,3 i can use {printf "%x,%d\n",$1,$2} but than i want to filter base on 1st hex digit 1st recrd (1 Reply)
Discussion started by: before4
1 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. Shell Programming and Scripting

Converting hex to ascii/decimal

I am writing a bash script to do some parsing on a log and I am running into a problem when it comes to converting only certain sections of the file from hex to ascii or hex to decimal. Data Example: The hex values after Hardware and SW Version I need to convert from Hex to ASCII and the... (16 Replies)
Discussion started by: Shiftkey
16 Replies

6. Programming

After converting the hexstr to Hex and storing the Hex in a char*

Hi All, My main intension of is to convert the Hexstring stored in a char* into hex and then prefixing it with "0x" and suffix it with ',' This has to be done for all the hexstring char* is NULL. Store the result prefixed with "0x" and suffixed with ',' in another char* and pass it to... (1 Reply)
Discussion started by: rvan
1 Replies

7. Shell Programming and Scripting

Converting hex value 7C (for pipe) to CRLF in Unix

I am trying to convert a txt file that includes one long string of data. The lines are separated with hex value 7C (for pipe). I am trying to process this file using SQR (Peoplesoft) so I thought the easiest thing to do would be to replace the eol char with a CRLF in unix so I can just... (4 Replies)
Discussion started by: sfedak
4 Replies

8. UNIX for Advanced & Expert Users

converting openssl hex dump or PEM format to integer array

Hello. I'm working on a project that involves creating public/private keys server-side using openssl and using the public key in a Javascript application to encrypt sensitive data in form fields before transmission to the server. Using an SSL https server connection was not an option in this... (1 Reply)
Discussion started by: jhopper
1 Replies

9. Shell Programming and Scripting

How to Convert Hex value to Dec ?

Hi All, I want to convert below Hex value to Dec value in each column .How to do it ? This data is in a 1 file. 4e20 0475 2710 010f 7530 69a2 7530 7e2f 4e20 02dd 7530 6299 4e20 0c0a 7530 69a2 4e20 0a0b 2710 0048 7530 7955 4e20 0d23 7530 622d 7530 9121 2710 001f 7530 7d3f (6 Replies)
Discussion started by: Nayanajith
6 Replies

10. Programming

converting hex to ascii

Hi everyone! I was wondering if anyone knows how to change hex code back into ascii. when i process a form: " / " turn to " %2F " " @ " turns to " %40 " " ' " turns to " %27 " " ( " turns to " %28 " " ) " turns to " %29 " this is my code so far: order.txt thanks, primal p.s.... (1 Reply)
Discussion started by: primal
1 Replies
Login or Register to Ask a Question