1993 and later versions of the Korn shell give you some other options. On Solaris 10, /bin/ksh is based on ksh88, but I believe /usr/dt/bin/dtksh should work (although i don't currently have access to a system to verify it).
If the hexadecimal values you're trying to convert can be represented in a long in the programming model used by the shell on your system, the script:
Code:
#!/usr/dt/bin/dtksh
while read -A a
do printf '%s' "${a[0]}"
for ((i = 1; i < ${#a[@]}; i++))
do
typeset -i2 b=0x${a[i]}
printf " %s" ${b:2}
done
echo
done < Input
should do what you want. If you have arbitrarily long strings of hexadecimal digits, to convert to binary, I think the following script does what you want:
Code:
#!/usr/dt/bin/dtksh
typeset -A b b1
b1['0']='0'; b['0']='0000'
b1['1']='1'; b['1']='0001'
b1['2']='10'; b['2']='0010'
b1['3']='11'; b['3']='0011'
b1['4']='100'; b['4']='0100'
b1['5']='101'; b['5']='0101'
b1['6']='110'; b['6']='0110'
b1['7']='111'; b['7']='0111'
b1['8']='1000'; b['8']='1000'
b1['9']='1001'; b['9']='1001'
b1['A']='1010'; b['A']='1010'
b1['B']='1011'; b['B']='1011'
b1['C']='1100'; b['C']='1100'
b1['D']='1101'; b['D']='1101'
b1['E']='1110'; b['E']='1110'
b1['F']='1111'; b['F']='1111'
b1['a']='1010'; b['a']='1010'
b1['b']='1011'; b['b']='1011'
b1['c']='1100'; b['c']='1100'
b1['d']='1101'; b['d']='1101'
b1['e']='1110'; b['e']='1110'
b1['f']='1111'; b['f']='1111'
while read -A a
do printf '%s' "${a[0]}"
for ((i = 1; i < ${#a[@]}; i++))
do printf ' %s' "${b1[${a[$i]:0:1}]}"
for ((j = 1; j < ${#a[$i]}; j++))
do printf '%s' "${b[${a[$i]:$j:1}]}"
done
done
echo
done < Input
I used the file Input containing:
Code:
WS-2 23 345 235
DT-3 45 4A3 000
pp-2 76 300 E4
hex 10 21 32 43 54 65 76 87 98 A9 BA CB DC ED FE 0F AbCdEf1
hex2long 1234567890ABCDEFabcdef1234567890abcdefABCDEF
as a test case using /bin/ksh on OS X. The values show in red produced different results from these two scripts. The output produced by the 1st script above is:
My question is:
i have a script called getevent
to run i just call ./getevent
can i convert this to make it binary executable and not letting my clients open it and see the code.??:(
I am using Solaris 8. (3 Replies)
All,
I want to convert multiple \0 005 characters to line feed 012 character
in a binary file to make to readable. Here is the sample od -c file
output:
0000000 254 355 \0 005 s r \0 * c o m . c i s c
Here is the sample od -b file output:
0000000 254 355 000... (0 Replies)
Hi frnds :)
I need a small help...
I have a very long file containing 20 digits decimal number which i want to convert into the corresponding 16 digit hexadecimal values.
File looks like....
11908486672755551741
05446378739602232559
04862605079740156652
.
.
.
I tried the script
for i... (7 Replies)
Hi,
I have got a library file, created by compiling C code. The file information with "file" command, gives it a "application/x-archive" type file. I want to extract the release string of my software from this file, so that i can know which version of C files were used to create the lib.
Can... (3 Replies)
Why would a binary which was compiled on a Solaris-10 not be runnable in a SunOS 5.10? (they are supposed to be precisely equivalent).
When I run the file command on it, it says:
ELF 32-bit LSB executable 80386 Version 1, dynamically linked, not stripped, no debugging information available... (10 Replies)
I have searched and the answers I have found thus far have led me to this point, so I feel I am just about there.
I am trying to convert a column of hexadecimal to decimal values so that I can filter out via grep just the data I want. I was able to pull my original 3 character hex value and... (10 Replies)
Hi Guys,
Is it possible to convert the hexadecimal to Binary by unix command.....I could not figure out....
If I need to convert AF6D to binary...what could be the way to do?
Thanks in advance!!
---------- Post updated at 02:57 AM ---------- Previous update was at 02:42 AM ----------
I... (6 Replies)
Dear all,
I am trying to write c-program to read the following file containing hexadecimal values (snippet of big data file).
I want to combine two hexadecimal values together like A0A03E01 and then would like to have the binary equivalent to perform further test on it. Unfortunately, it failed... (16 Replies)