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

binStr = '11111111';

%
% You can represent this value as a hexadecimal number using bin2dec and dec2hex together. The output of dec2hex is a character vector.

D = bin2dec(binStr)

%

hexStr = dec2hex(D)

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

D = 0b11111111

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

hexStr = dec2hex(D)

% Copyright 2019 The MathWorks, Inc.