Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

bin2hex()

Display binary data as two lowercase hexadecimal digits per byte, including leading zero nibbles.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

bin2hex(string $string): string

Display binary data as two lowercase hexadecimal digits per byte, including leading zero nibbles. It operates on the stored bytes, so the text "10" becomes the codes for the two characters rather than hexadecimal ten.

Signature

bin2hex(string $string): string

Example output

["000fff","3130",""]

Examples

<?php
echo json_encode([bin2hex("\x00\x0F\xFF"),bin2hex("10"),bin2hex("")]);

Result

["000fff","3130",""]

Sources