MATLAB 帮助中心
fi 对象的存储整数的十六进制表示
fi
b = hex(a)
b = hex(a) 以十六进制格式返回 fi 对象 a 的存储整数作为字符向量。
b
a
定点数可以表示为
real-world value=2−fraction length×stored integer
或者,等效于
real-world value=(slope×stored integer)+bias
此存储整数是原始二进制数字,其中假定二进制小数点位于字的最右侧。
提示
hex 返回 fi 对象的存储整数的十六进制表示。要获取 fi 对象的真实值的十六进制表示,请使用 dec2hex。
hex
dec2hex
示例
全部折叠
创建一个有符号 fi 对象,值为 -1 和 1,字长为 8 位,小数长度为 7 位。
-1
1
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 = '80 7f'
此示例说明如何将十六进制数据从 MATLAB® 工作区写入文本文件。
定义您的数据并创建一个名为 hexdata.txt 的可写文本文件。
hexdata.txt
x = (0:15)'/16; a = fi(x, 0, 16, 16); h = fopen('hexdata.txt', 'w');
使用 fprintf 函数将数据写入 hexdata.txt 文件。
fprintf
for k = 1:length(a) fprintf(h, '%s\n', hex(a(k))); end fclose(h);
要查看您创建的文件的内容,请使用 type 函数。
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 变量中的十六进制值。
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
输入数组,指定为 fi 对象。
数据类型: fi
在 R2006a 之前推出
bin | dec | storedInteger | oct | dec2hex | dec2base | dec2bin
bin
dec
storedInteger
oct
dec2base
dec2bin
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
欧洲
亚太
联系您当地的办事处