Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

php
binary
communitycreator

How to decode a hexadecimal string in PHP

Dario Vincenzo Tarantini

The hex2bin method in PHP can be used to convert a hexadecimally encoded string to a binary string. However, this method doesn’t convert a hexadecimal number to a binary number.

Syntax

hex2bin(string $string): string|false

Parameters

hex2bin takes the hex string that will be converted to a binary string as a parameter.

Return value

The hex2bin method returns a string upon success; otherwise, it returns false.

Code

In this example, we are going to decode the encoded string Hello, educative!.

<?php

echo hex2bin("48656c6c6f2c2065647563617469766521");

RELATED TAGS

php
binary
communitycreator

CONTRIBUTOR

Dario Vincenzo Tarantini
RELATED COURSES

View all Courses

Keep Exploring