Sponsored Content
Top Forums Shell Programming and Scripting Hexadecimal to Binary conversion Post 302844797 by Jotne on Tuesday 20th of August 2013 04:07:40 AM
Old 08-20-2013
awk
Code:
echo "AF6D" | awk 'BEGIN {
	FS=""
	a["f"]="1111"
	a["e"]="1110"
	a["d"]="1101"
	a["c"]="1100"
	a["b"]="1011"
	a["a"]="1010"
	a["9"]="1001"
	a["8"]="1000"
	a["7"]="0111"
	a["6"]="0110"
	a["5"]="0101"
	a["4"]="0100"
	a["3"]="0011"
	a["2"]="0010"
	a["1"]="0001"
	a["0"]="0000"
	}
	{
	for (i=1;i<=NF;i++) printf a[tolower($i)]
	print ""
	}'
1010111101101101

Edit: other version found on unix.com
Code:
echo "AF6D" | awk --non-decimal-data ' {
for(i=lshift(1,15);i;i=rshift(i,1))
printf "%d%s", (and(("0x"$1)+0,i) > 0), ++c%4==0?" ":"";
printf"\n"; }'
1010 1111 0110 1101


Last edited by Jotne; 08-20-2013 at 05:13 AM..
This User Gave Thanks to Jotne For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

shell script conversion to binary

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)
Discussion started by: bcheaib
3 Replies

2. UNIX for Dummies Questions & Answers

Binary file conversion

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)
Discussion started by: bubba112557
0 Replies

3. Shell Programming and Scripting

Decimal to Hexadecimal conversion

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)
Discussion started by: vanand420
7 Replies

4. Programming

Binary conversion function

Is/are there any function(s) in C that convert(s) character/ASCII/Decimal to binary and vice versa? what about bcopy and strcpy? (1 Reply)
Discussion started by: Peevish
1 Replies

5. Shell Programming and Scripting

binary file conversion

Hello folks, i have a binary text file but i am not able to convert into text format, please suggest. thanks. (2 Replies)
Discussion started by: learnbash
2 Replies

6. Shell Programming and Scripting

binary to ascii conversion

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)
Discussion started by: atulmt
3 Replies

7. Solaris

binary conversion

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)
Discussion started by: steve701
10 Replies

8. Shell Programming and Scripting

NAWK conversion of hexadecimal input to decimal output via printf, I am close I can feel it

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)
Discussion started by: PCGameGuy
10 Replies

9. Shell Programming and Scripting

Conversion from Hexadecimal to binary

How can I convert hexadecimal values to Binary from the second field to the end Input: WS-2 23 345 235 DT-3 45 4A3 000 pp-2 76 300 E4 Output: WS-2 100011 1101000101 1000110101 DT-3 1000101 10010100011 000 pp-2 1110110 1100000000 11100100 (16 Replies)
Discussion started by: aydj
16 Replies

10. Programming

Hexadecimal to binary operation

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)
Discussion started by: emily
16 Replies
HEXDEC(3)								 1								 HEXDEC(3)

hexdec - Hexadecimal to decimal

SYNOPSIS
number hexdec (string $hex_string) DESCRIPTION
Returns the decimal equivalent of the hexadecimal number represented by the $hex_string argument. hexdec(3) converts a hexadecimal string to a decimal number. hexdec(3) will ignore any non-hexadecimal characters it encounters. PARAMETERS
o $hex_string - The hexadecimal string to convert RETURN VALUES
The decimal representation of $hex_string EXAMPLES
Example #1 hexdec(3) example <?php var_dump(hexdec("See")); var_dump(hexdec("ee")); // both print "int(238)" var_dump(hexdec("that")); // print "int(10)" var_dump(hexdec("a0")); // print "int(160)" ?> NOTES
Note The function can convert numbers that are too large to fit into the platforms integer type, larger values are returned as float in that case. SEE ALSO
dechex(3), bindec(3), octdec(3), base_convert(3). PHP Documentation Group HEXDEC(3)
All times are GMT -4. The time now is 03:46 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy