Hex to decimal conversion 32 Bit (single precision)
Versión 1.0.2 (2,41 KB) por
BerndS
Calculate decimal representation from a 32-digit (single precision) binary number according to specification of IEEE754.
% Calculate decimal representation from a 32-digit (single precision)
% binary number according to specification of IEEE754.
% The input is a string consisting of a valid number of hexadecimal
% characters (see examples).
% Formula symbols:
% exp: Exponent
% m: mantissa
% s: sign
% r: number bits of exponent
% p: number bits of mantissa
% b: bias
% Examples:
% Exp = 0; m = 0:
% out = IEEE754_Hex2Dec32Bit("00000000") returns 0
% out = IEEE754_Hex2Dec32Bit("80000000") returns 0
% Exp = 0; m > 0 (denormalised number):
% out = IEEE754_Hex2Dec32Bit("007fffff") returns 1.175494210692441e-38
% 0 < exp < 2^r-1; m >= 0 (normalised number):
% out = IEEE754_Hex2Dec32Bit("40ffffff") returns 7.999999523162842
% exp = 2^r-1; m = 0 (+/-infinity):
% out = IEEE754_Hex2Dec32Bit("ff800000") returns -Inf
% out = IEEE754_Hex2Dec32Bit("7f800000") returns Inf
% exp = 2^r-1; m > 0 (not a number)
% out = IEEE754_Hex2Dec32Bit("ffc00000") returns NaN
% out = IEEE754_Hex2Dec32Bit("ffc00001") returns NaN
% Written by Bernd Seggewiß
% Published 17/08/23
% Version 1.0.0
% Version 1.0.1:
% Date: 11/11/24
% - Addition of funtion CUSTOM_BIN2DEC. Convert binary string to decimal.
% decimalValue = CUSTOM_BIN2DEC(binaryStr) takes a binary string
% 'binaryStr' as input and returns its decimal equivalent 'decimalValue'.
% The function processes each character in the string, calculates
% the corresponding power of 2, and accumulates the total to produce
% the final decimal value.
% - Supplemented by the following checks:
% ~ischar(hexString): Checks if hexString is not a character array.
% ~all(ismember(hexString, '0123456789abcdefABCDEF')): Checks if all
% characters in hexString are valid hexadecimal characters (0-9 and a-f or A-F).
% length(hexString) ~= 8: Checks if the length of hexString is not equal to 8.
% Version 1.0.2:
% Date: 15/11/24
% Addition of function custom_hexToBinaryVector. It converts hexadecimal
% string to a binary vector.
Citar como
BerndS (2026). Hex to decimal conversion 32 Bit (single precision) (https://la.mathworks.com/matlabcentral/fileexchange/133962-hex-to-decimal-conversion-32-bit-single-precision), MATLAB Central File Exchange. Recuperado .
Compatibilidad con la versión de MATLAB
Se creó con
R2023b
Compatible con R2023b
Compatibilidad con las plataformas
Windows macOS LinuxEtiquetas
Descubra Live Editor
Cree scripts con código, salida y texto formateado en un documento ejecutable.
