8.8表示法.... [英] 8.8 notation....
问题描述
我有8.8表示法中的数字我希望转换为浮点数.......
8.8表示法是16位固定表示法,所以:
0xFF11是数字255.17
0x0104是数字1.4
0x2356是数字35.86
等等....
关于如何将其转换为浮点数的任何想法?
John
I have a number in 8.8 notation that I wish to convert to a float.......
8.8 notation is a 16 bit fixed notation, so:
0xFF11 is the number 255.17
0x0104 is the number 1.4
0x2356 is the number 35.86
and so on....
Any ideas on how to convert this into a float?
John
推荐答案
2003年10月1日星期三,John T.写道:
On Wed, 1 Oct 2003, John T. wrote:
我有一个8.8符号的数字,我希望转换为浮点数... ............ 8.8表示法是一个16位固定表示法,所以:
0xFF11是数字255.17
0x0104是数字1.4
0x2356是数字35.86 >等等....
有关如何将其转换为浮动的任何想法?
I have a number in 8.8 notation that I wish to convert to a float.......
8.8 notation is a 16 bit fixed notation, so:
0xFF11 is the number 255.17
0x0104 is the number 1.4
0x2356 is the number 35.86
and so on....
Any ideas on how to convert this into a float?
首先,你*做*意识到你的8.8表示法
指定的
不是一对一的功能,对吗?对于
示例,如果0x0104等于1.4,那么0x008C也是如此。
但是你可以按照要求去...
/ *原始数字* /
unsigned int eight_eight = 0x0104;
/ *提取字段* /
unsigned int int_part = eight_eight>> 8;
unsigned int frac_part = eight_eight& 0xFF;
/ *将它重新组合在一起* /
double result = int_part + frac_part / 100.0;
(或者在一个函数中:)
double from_88(unsigned int val)
{
/ * no错误检查''val''* * /
返回(val>> 8)+(val& 0xFF)/ 100 .;
}
unsigned int to_88(double val)
{
/ *没有错误检查''val''* /
unsigned int ival =(unsigned int)val;
unsigned int fval =(unsigned int)(100 *(val-ival)+ 0.5);
返回(ival<< 8)+ fval;
}
HTH,
-Arthur
First of all, you *do* realize that your "8.8 notation"
as specified is not a one-to-one function, right? For
example, if 0x0104 is equal to 1.4, then so is 0x008C.
But here you go, as requested...
/* the original number */
unsigned int eight_eight = 0x0104;
/* extract the fields */
unsigned int int_part = eight_eight >> 8;
unsigned int frac_part = eight_eight & 0xFF;
/* put it back together right-ways */
double result = int_part + frac_part/100.0;
(Or in a function:)
double from_88(unsigned int val)
{
/* no error-checking on range of ''val'' */
return (val>>8) + (val & 0xFF)/100.;
}
unsigned int to_88(double val)
{
/* no error-checking on range of ''val'' */
unsigned int ival = (unsigned int) val;
unsigned int fval = (unsigned int) (100*(val-ival) + 0.5);
return (ival << 8) + fval;
}
HTH,
-Arthur
2003年10月1日星期三,Arthur J. O''Dwyer写道:
On Wed, 1 Oct 2003, Arthur J. O''Dwyer wrote:
周三, 2003年10月1日,John T.写道:
On Wed, 1 Oct 2003, John T. wrote:
我有一个8.8表示法中的数字,我希望转换为浮点数.......
8.8表示法是一个16 b它修复了表示法,所以:
0xFF11是数字255.17
0x0104是数字1.4
0x2356是数字35.86
I have a number in 8.8 notation that I wish to convert to a float.......
8.8 notation is a 16 bit fixed notation, so:
0xFF11 is the number 255.17
0x0104 is the number 1.4
0x2356 is the number 35.86
首先,你* *确认您指定的8.8表示法不是一对一的功能,对吗?例如,如果0x0104等于1.4,那么0x008C也是如此。
First of all, you *do* realize that your "8.8 notation"
as specified is not a one-to-one function, right? For
example, if 0x0104 is equal to 1.4, then so is 0x008C.
等一下...我发现那条消息后就意识到了
,我无法想到*任何*合理的方法从浮点值1.4获得0x0104
!如果0x0104是1.4,那么
什么是1.04? 0x0140在你的
表示法中代表什么?
如果你真的没有在那里打错,那可能是
a *真的*有趣的格式...
我的解决方案假设你的意思是0x140< ==> 1.4,BTW。
-Arthur
Wait a minute... I realized as soon as I sent that message
that I can''t think of *any* reasonable way to get 0x0104
from the floating-point value 1.4! If 0x0104 is 1.4, then
what''s 1.04? And what does 0x0140 represent in your
notation?
If you really didn''t make a typo there, this could be
a *really* interesting format...
My solution assumes you meant 0x140 <==> 1.4, BTW.
-Arthur
" John T." <乔** @ dat.com>写道:
"John T." <jo**@dat.com> wrote:
我有8.8表示法中的数字我希望转换为浮点数.......
8.8表示法是16位固定表示法,所以:
0xFF11是数字255.17
0x0104是数字1.4
0x2356是数字35.86
等等....
关于如何转换这个的任何想法浮动?
I have a number in 8.8 notation that I wish to convert to a float.......
8.8 notation is a 16 bit fixed notation, so:
0xFF11 is the number 255.17
0x0104 is the number 1.4
0x2356 is the number 35.86
and so on....
Any ideas on how to convert this into a float?
是的:手工制作。 C对此没有任何作用,因为定点类型不是C的一部分。但是,自己编写一个并不困难。
提示: %,/,0x100和/或0xFF,(浮动),+。
Richard
Yes: by hand. C has no function for this, since fixed-point types are
not part of C. However, it wouldn''t be hard to write one yourself.
Hints: %, /, 0x100 and/or 0xFF, (float), +.
Richard
这篇关于8.8表示法....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!