hex
fi
对象的存储整数的十六进制表示
说明
示例
查看十六进制格式的 fi
对象的存储整数
创建一个有符号 fi
对象,值为 -1
和 1
,字长为 8 位,小数长度为 7 位。
a = fi([-1 1], 1, 8, 7)
a = -1.0000 0.9922 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 8 FractionLength: 7
查找 fi
对象 a
的存储整数的十六进制表示。
b = hex(a)
b = '80 7f'
将十六进制数据写入文件
此示例说明如何将十六进制数据从 MATLAB 工作区写入文本文件。
定义您的数据并创建一个名为 hexdata.txt
的可写文本文件。
x = (0:15)'/16; a = fi(x, 0, 16, 16); h = fopen('hexdata.txt', 'w');
使用 fprintf
函数将数据写入 hexdata.txt
文件。
for k = 1:length(a) fprintf(h, '%s\n', hex(a(k))); end fclose(h);
要查看您创建的文件的内容,请使用 type
函数。
type hexdata.txt
0000 1000 2000 3000 4000 5000 6000 7000 8000 9000 a000 b000 c000 d000 e000 f000
从文件中读取十六进制数据
此示例说明如何将文本文件中的十六进制数据读回 MATLAB 工作区。
定义您的数据,创建一个名为 hexdata.txt
的可写文本文件,并将您的数据写入 hexdata.txt
文件。
x = (0:15)'/16; a = fi(x, 0, 16, 16); h = fopen('hexdata.txt', 'w'); for k = 1:length(a) fprintf(h, '%s\n', hex(a(k))); end fclose(h);
打开 hexdata.txt
进行读取,并将其内容读入工作区变量
h = fopen('hexdata.txt', 'r'); nextline = ''; str = ''; while ischar(nextline) nextline = fgetl(h); if ischar(nextline) str = [str; nextline]; end end fclose(h);
创建一个具有正确定标的 fi
对象,并为其赋予存储在 str
变量中的十六进制值。
b = fi([], 0, 16, 16); b.hex = str
b = 0 0.0625 0.1250 0.1875 0.2500 0.3125 0.3750 0.4375 0.5000 0.5625 0.6250 0.6875 0.7500 0.8125 0.8750 0.9375 DataTypeMode: Fixed-point: binary point scaling Signedness: Unsigned WordLength: 16 FractionLength: 16
输入参数
a
— 输入数组
fi
对象
输入数组,指定为 fi
对象。
数据类型: fi
版本历史记录
在 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)