bin2hex

The bin2hex function converts any string into an ASCII string containing the hexadecimal represenation of the original string. As the name of the function suggests, bin2hex is particularly useful to make a human-readable representation of binary strings.

PHP

$binary_string = pack("nvc*", 0x1234, 0x5678, 65, 66);

echo bin2hex($binary_string);

=> // 123478564142

Ruby doesn’t have a function equivalent to PHP’s bin2hex, but Bytes::unpack with a format string of H* will achieve the same functionality.

Ruby

a = [0x1234, 0x5678, 65, 66];

binary_string = a.pack("nvc*");

puts binary_string.unpack('H*');
=> # 123478564142
By | 2009-06-24T13:35:42+00:00 June 22nd, 2009|Categories: PHP, Ruby|Tags: , , , , , |Comments Off on bin2hex

About the Author:

This Is A Custom Widget

This Sliding Bar can be switched on or off in theme options, and can take any widget you throw at it or even fill it with your custom HTML Code. Its perfect for grabbing the attention of your viewers. Choose between 1, 2, 3 or 4 columns, set the background color, widget divider color, activate transparency, a top border or fully disable it on desktop and mobile.

This Is A Custom Widget

This Sliding Bar can be switched on or off in theme options, and can take any widget you throw at it or even fill it with your custom HTML Code. Its perfect for grabbing the attention of your viewers. Choose between 1, 2, 3 or 4 columns, set the background color, widget divider color, activate transparency, a top border or fully disable it on desktop and mobile.