hex2num
将 IEEE 十六进制格式转换为双精度数
说明
示例
将十六进制格式转换为带小数部分的数
使用十六进制数字创建一个字符向量,它表示一个 IEEE® 格式双精度数。
hexStr = '400921fb54442d18';
要将其转换为它所表示的数,请使用 hex2num
函数。如果 hexStr
表示具有小数部分的数,则 hex2num
会正确转换该数字。
X = hex2num(hexStr)
X = 3.1416
您可以使用 num2hex
函数将 X
转换回其十六进制表示。
num2hex(X)
ans = '400921fb54442d18'
转换负数、NaN 和 Inf 的十六进制表示
创建一个表示负数的字符向量。然后转换它。
hexStr = 'BFF';
X = hex2num(hexStr)
X = -1
转换 NaN
的表示。
hex2num('FFF8')
ans = NaN
转换 Inf
的表示。
hex2num('7FF')
ans = Inf
返回双精度数组
使用十六进制数字创建一个字符串数组,它表示多个 IEEE® 格式的数。
hexStr = ["4005bf0b0d7a3c06" "3fc189374bc6a7f0" "402c"]
hexStr = 1x3 string
"4005bf0b0d7a3c06" "3fc189374bc6a7f0" "402c"
转换 hexStr
,并将其以双精度数的数组形式返回。
X = hex2num(hexStr)
X = 1×3
2.7183 0.1370 14.0000
输入参数
hexStr
— 表示十六进制数的文本
字符数组 | 字符向量元胞数组 | 字符串数组
表示十六进制数的文本,指定为字符数组、字符向量元胞数组或字符串数组。
如果
hexStr
是字符向量元胞数组或字符串数组,则hex2num
会将每个元素转换为一个数字。如果
hexStr
是字符数组,则hex2num
将每行转换为一个数字。
扩展功能
C/C++ 代码生成
使用 MATLAB® Coder™ 生成 C 代码和 C++ 代码。
用法说明和限制:
如果
hex2num
的输出为空,则生成的代码返回0
×1
数组,而不是0
×0
数组。
基于线程的环境
使用 MATLAB® backgroundPool
在后台运行代码或使用 Parallel Computing Toolbox™ ThreadPool
加快代码运行速度。
此函数完全支持基于线程的环境。有关详细信息,请参阅在基于线程的环境中运行 MATLAB 函数。
版本历史记录
在 R2006a 之前推出
MATLAB 命令
您点击的链接对应于以下 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:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)