%% Convert Hexadecimal Value to Binary
% Create a character vector that represents a hexadecimal value.

hexStr = 'FF';

%
% You can represent this value as a binary number using hex2dec and dec2bin together. The output of dec2bin is a character vector.

D = hex2dec(hexStr)

%

binStr = dec2bin(D)

%
% As an alternative, starting in R2019b you can specify a number as a hexadecimal literal, and convert it directly using the dec2bin function.
% When you specify a hexadecimal literal, use the 0x prefix, and do not use quotation marks. MATLAB® stores its value as an unsigned integer that has the appropriate size.

D = 0xFF

%
% Convert D to a character vector that represents D as a binary number.

binStr = dec2bin(D)

%
% Copyright 2019 The MathWorks, Inc.