File Exchange

image thumbnail

Hexadecimal to binary

version 1.0.0.0 (1.13 KB) by Michael Chenoweth
converts a hexadecimal string of just about any length to the proper binary equivalent

16 Downloads

Updated 27 May 2009

View License

this will do the easy conversion for you without any truncating or improper values. It puts it in matrix format for easier manipulation.

hex2bin('0123456789abcdef')

ans =

Columns 1 through 18

0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 0 1

Columns 19 through 36

0 0 0 1 0 1 0 1 1 0 0 1 1 1 1 0 0 0

Columns 37 through 54

1 0 0 1 1 0 1 0 1 0 1 1 1 1 0 0 1 1

Columns 55 through 64

0 1 1 1 1 0 1 1 1 1

Cite As

Michael Chenoweth (2021). Hexadecimal to binary (https://www.mathworks.com/matlabcentral/fileexchange/24282-hexadecimal-to-binary), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (6)

Popov Yuri

Bomba!!!!!!

Josh

Works great, just be careful about case. Use the lower() function modify the case of the hex string.

Josh

Dominic Wu

Pedro valdez

James Tursa

This function has several problems, hence the low rating.

- No help included
- No first help line
- Does not do *any* argument checking
- Does not allow for uppercase hex characters
- Does not allow for arrays of character strings as input

If you pass this function some invalid text like 'garbage', it will happily give you an answer with no warning whatsoever that your input is junk. Or if you pass it an array like ['abc';'def'], it will not process the 2nd line.

MATLAB Release Compatibility
Created with R2007a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!