How to encode data in hexadecimal?

123 Views Asked by At

The code:

#0c0f56415445532d413636373231343939

Is: VATES-A66721499 but encoded in hex.

I have made the following attempt:

$hex = bin2hex('VATES-A66721499');
echo $hex;

output:

56415445532d413636373231343939

But I need to get this other part:

#0c0f

I have tried the following but no result: #0c0f56415445532d413636373231343939

1

There are 1 best solutions below

0
On BEST ANSWER

0c and 0f are unprintable control characters, and # is not part of hexadecimal encoding at all.

You can either:

'#' . bin2hex("\x0c\x0f" . 'VATES-A66721499')

Or:

'#0c0f' . bin2hex('VATES-A66721499')

Both will give the desired output.