Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

hex2bin(3) [php man page]

HEX2BIN(3)								 1								HEX2BIN(3)

hex2bin - Decodes a hexadecimally encoded binary string

SYNOPSIS
string hex2bin (string $data) DESCRIPTION
Decodes a hexadecimally encoded binary string. Caution This function does NOT convert a hexadecimal number to a binary number. This can be done using the base_convert(3) function. PARAMETERS
o $data - Hexadecimal representation of data. RETURN VALUES
Returns the binary representation of the given data or FALSE on failure. ERRORS
/EXCEPTIONS If the hexadecimal input string is of odd length or invalid hexadecimal string an E_WARNING level error is thrown. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.5.1 | | | | | | | A warning is thrown if the input string is | | | invalid hexadecimal string. | | | | | 5.4.1 | | | | | | | A warning is thrown if the input string is of | | | odd length. In PHP 5.4.0 the string was silently | | | accepted, but the last byte was truncated. | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 hex2bin(3) example <?php $hex = hex2bin("6578616d706c65206865782064617461"); var_dump($hex); ?> The above example will output something similar to: string(16) "example hex data" SEE ALSO
bin2hex(3), unpack(3). PHP Documentation Group HEX2BIN(3)

Check Out this Related Man Page

DECHEX(3)								 1								 DECHEX(3)

dechex - Decimal to hexadecimal

SYNOPSIS
string dechex (int $number) DESCRIPTION
Returns a string containing a hexadecimal representation of the given unsigned $number argument. The largest number that can be converted is PHP_INT_MAX * 2 + 1 (or -1): on 32-bit platforms, this will be 4294967295 in decimal, which results in dechex(3) returning ffffffff. PARAMETERS
o $number - The decimal value to convert. As PHP's integer type is signed, but dechex(3) deals with unsigned integers, negative integers will be treated as though they were unsigned. RETURN VALUES
Hexadecimal string representation of $number. EXAMPLES
Example #1 dechex(3) example <?php echo dechex(10) . " "; echo dechex(47); ?> The above example will output: a 2f Example #2 dechex(3) example with large integers <?php // The output below assumes a 32-bit platform. // Note that the output is the same for all values. echo dechex(-1)." "; echo dechex(PHP_INT_MAX * 2 + 1)." "; echo dechex(pow(2, 32) - 1)." "; ?> The above example will output: ffffffff ffffffff ffffffff SEE ALSO
hexdec(3), decbin(3), decoct(3), base_convert(3). PHP Documentation Group DECHEX(3)
Man Page

13 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Binary and hex in unix

not much familiar with binary and hex calculation in script programming.... explaination: binary format control the parameter turned on or off in the program stored in hex mode, the question is: how to change 39e to 19e using the binary calculation(although i don't know the command for... (2 Replies)
Discussion started by: trynew
2 Replies

2. Shell Programming and Scripting

Get Hexadecimal Value

I have a record in a file that ends with the new line character "\n". How dio I determine the hexadecimal value for that? (2 Replies)
Discussion started by: lesstjm
2 Replies

3. UNIX for Advanced & Expert Users

Modifying binary file by editing Hex values ?

Hi , i'm using special binary file (lotus notes) and modifying an hexadecimal address range with windows hex editor and it works fine ! The file is an AIX one and i'm forced to transfert (ftp) it before modifying it and re-transfert ! NOW i would do this directly under AIX ! I can... (4 Replies)
Discussion started by: Nicol
4 Replies

4. UNIX for Advanced & Expert Users

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.... (6 Replies)
Discussion started by: rajan_ka1
6 Replies

5. Shell Programming and Scripting

parsing a hex file

Goodmorning, I have a hex encoded file that needs to be parsed to remove some bytes and write the remaining ones to a new file. Here is the top of the file as shown by a hex editor: http://www.wallpaperdepot.com/images/unix/TopofFile.gif The first parse exercise is to remove bytes 0-87... (6 Replies)
Discussion started by: philplasma
6 Replies

6. Programming

ascii to hex

Hello guys, i want to convert a text file to hex and have written this code : int main(int argc, char **argv) { ifstream file; string fileName = "CODEZ"; file.open(fileName.c_str()); // oeffen im Text-Modus if(file) {... (5 Replies)
Discussion started by: Kingbruce
5 Replies

7. Shell Programming and Scripting

Hex numbering sequence

Friends, I am looking for a small script which generates HEX sequence. Input to the script is starting hex number - Group ID and number of members a group should have and total groups. e.g: Here we are generating 2 groups with 4 Members each starting with hex 036A. Output: Group ID 036A,... (5 Replies)
Discussion started by: dynamax
5 Replies

8. Shell Programming and Scripting

Get the places of binary digits in the korn shell script

TO THE ALMIGHTY FORUM , though i have already posted the same question on hex to binary thread , i am posting here also for other beginners who may benefit from this thread... I have a 32 bit binary containing a series of 1' and 0's , and i am stuck... (2 Replies)
Discussion started by: venu
2 Replies

9. Shell Programming and Scripting

convert hex to binary and send to variable

Folks, can anyone help with a script to convert hex to binary digits, and break the 32 bit binary into packs of 4 and send them to 8 different variables.Any help is sincerely appreciated. Thanks venu Its in korn shell...... (24 Replies)
Discussion started by: venu
24 Replies

10. Programming

How to find length of string and pass into char array in C?

Hi All I want to take a Hexadecimal number as input and i want to find lenth of the input and pass it to char s ( char s ). I have a program to convert hexadecial to binary but it is taking limited input but i want to return binary number based on input. How? (1 Reply)
Discussion started by: atharalikhan
1 Replies

11. Shell Programming and Scripting

how to get data from hex file using SED or AWK based on pattern sign

I have a binary (hex) file I need to parse to get some data which are encoded this way: .* b4 . . . 01 12 .* af .* 83 L1 x1 x2 xL 84 L2 y1 y2 yL By another words there is a stream of hexadecimal bytes (in my example separated by space for better readability). I need to get value stored in... (3 Replies)
Discussion started by: sameucho
3 Replies

12. Shell Programming and Scripting

Hexadecimal to Binary conversion

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

13. Shell Programming and Scripting

Regex and backreference to replace in binary file

Hello to all, I have this sed script that replaces hex strins within a binary file. As you can see, I want to replace all bytes 4X with 2X (where X could take values 0 to F). sed -e 's/\x40/\x20/g' -e 's/\x41/\x21/g' -e 's/\x42/\x22/g' -e 's/\x43/\x23/g' -e 's/\x44/\x24/g' -e... (7 Replies)
Discussion started by: Ophiuchus
7 Replies