%% Convert Binary Number to Hexadecimal
% Starting in R2019b, you can write numbers as binary or hexadecimal literals, using the 0b and 0x prefixes. MATLAB® interprets and stores these literals as ordinary numbers, which the dec2hex function can convert to character arrays representing hexadecimal values.
% Write a number as a binary literal. It is stored as an unsigned integer with an appropriate size.

b = 0b11111111

%
% Convert it to a character vector using dec2hex.

hexStr = dec2hex(b)

%
% As an alternative, in any version of MATLAB, you can represent the binary number by a character vector, and convert it using the bin2dec and dec2hex functions together. When using bin2dec, do not write the 0b prefix.

binStr = '11111111';
D = bin2dec(binStr)

%

hexStr = dec2hex(D)

% Copyright 2019 The MathWorks, Inc.