帮助中心帮助中心
将单精度数和双精度数转换为 IEEE 十六进制格式
hexStr = num2hex(X)
示例
hexStr = num2hex(X) 使用十六进制数字返回 X 的 IEEE® 格式表示形式。
X
如果 X 是双精度数,则 hexStr 有 16 个字符。
hexStr
如果 X 是单精度数,则 hexStr 有 8 个字符。
如果 X 是向量、矩阵或多维数组,则 hexStr 是二维字符数组。hexStr 的每行表示 X 的一个元素。
与 dec2hex 函数不同,num2hex 可以转换具有小数部分的浮点值。此外,num2hex 能够正确处理 NaN 和 Inf 值以及非正规数。
dec2hex
num2hex
NaN
Inf
num2hex 生成的格式与 format hex 命令生成的格式相同。
format hex
全部折叠
创建一个数,并用十六进制数字将其表示为 IEEE® 格式。X 是双精度数,并且有小数部分。
X = 3.1416; hexStr = num2hex(X)
hexStr = '400921ff2e48e8a7'
由于 hexStr 是 IEEE 格式,它也表示 X 的小数部分。您可以使用 hex2num 函数将 hexStr 转换回数字。
hex2num
hex2num(hexStr)
ans = 3.1416
创建一个单精度数。
X = single(2.7182818)
X = single 2.7183
转换 X。num2hex 函数仅使用八个十六进制数字表示单精度数。
hexStr = '402df854'
转换一个负数并用 IEEE® 格式表示它。
num2hex(-1)
ans = 'bff0000000000000'
转换 NaN。
num2hex(NaN)
ans = 'fff8000000000000'
转换 Inf。
num2hex(Inf)
ans = '7ff0000000000000'
创建一个数值数组。
X = [3.1416 1.37e-5 1023.92];
转换 X 的元素。num2hex 函数返回表示这些值的字符数组。
hexStr = 3x16 char array '400921ff2e48e8a7' '3eecbb21a99df39b' '408fff5c28f5c28f'
输入数组,指定为数值数组。
数据类型: single | double
single
double
backgroundPool
ThreadPool
此函数完全支持基于线程的环境。有关详细信息,请参阅在基于线程的环境中运行 MATLAB 函数。
在 R2006a 之前推出
hex2num | dec2hex | format
format
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office