比特缠绕/操纵问题 [英] Bit twiddling/manipulation question

查看:59
本文介绍了比特缠绕/操纵问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在双数据类型中存储两个浮点值(每个值需要更少的16位

存储)。


任何人都可以给我用一些宏来检索/存储双倍的价值?





STORE_LOWWORD(存储,值)

GET_LOWWORD(存储)/ *返回值* /

STORE_HIGHWORD(存储,值)

GET_HIGHWORD(存储)/ *返回值* /

I need to store two float values (each of which requires less 16 bit
storage), in a double data type.

Can anyone give me some macros to retrive/store values in the double ?

something along the lines of

STORE_LOWWORD(storage, value)
GET_LOWWORD(storage) /* returns value */
STORE_HIGHWORD(storage, value)
GET_HIGHWORD(storage) /* returns value */

推荐答案

Bartholomew Simpson< 12 ********** @ terrace.comwrote:

#我需要在双数据类型中存储两个浮点值(每个值需要较少的16位

#存储)。



#任何人都可以给我一些宏来检索/存储双倍的值?

浮点值的格式特定于系统,例如DEC F或

IEEE单精确。你不会得到一小部分代码,

无处不在。你可以得到一些运行在某处的代码,

或者到处运行的大量代码。


你最终可能会做一些像< br $> b $ b union {

struct {

unsigned signbit:1;

int exponent:6;

unsigned fraction:9;

}部分;

短包装;

} smallreal;

union {

struct {

unsigned signbit:1;

int exponent:11;

unsigned fraction:20;

}部分;

浮动包装;

}真实;

real.packed = floatvalue;

smallreal.parts.signbit = real.parts.signbit;

smallreal.parts.exponent = real.parts.exponent-11;

smallreal.parts .fraction = real.parts.fraction>> 11;


我使用了联合会和结构,因为你不能使用强制转换将
a浮点值转换为相同的位模式现在称为整数,也不是
反之亦然。你必须使用

union aliassing或memcpy来传递struct或char数组。


在DSP世界里有小的实际格式,?μlaw或者什么

就是这样。你可以查看一下,看看是否所有这些小的b
格式是可以接受的,并且如果已经在

上定义了你要运行的系统。


-

SM Ryan http://www.rawbw.com/~wyrmwif/

你在这里经营什么样的便利店?
Bartholomew Simpson <12**********@terrace.comwrote:
# I need to store two float values (each of which requires less 16 bit
# storage), in a double data type.
#
# Can anyone give me some macros to retrive/store values in the double ?

The format of float values is specific to the system, such DEC F or
IEEE single precision. You''re not going to get a small bit of code that
runs everywhere. You can get a small bit of code that runs somewhere,
or a big chunk of code that runs everywhere.

You may end up doing some like
union {
struct {
unsigned signbit: 1;
int exponent: 6;
unsigned fraction: 9;
} parts;
short packed;
} smallreal;
union {
struct {
unsigned signbit: 1;
int exponent: 11;
unsigned fraction: 20;
} parts;
float packed;
} real;
real.packed = floatvalue;
smallreal.parts.signbit = real.parts.signbit;
smallreal.parts.exponent = real.parts.exponent-11;
smallreal.parts.fraction = real.parts.fraction>>11;

I used unions and structs because you cannot use a cast to convert
a float value to the same bit pattern now called an integer nor
vice versa. You have to pass through struct or char array using
union aliassing or memcpy.

In the DSP world there are small real formats, ?μlaw or something
like that. You can look that up and see if all these small
formats are acceptable and if transformers are already defined on
the systems that you want to run on.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
What kind of convenience store do you run here?




" Bartholomew Simpson" < 12 ********** @ terrace.comwrote in message

news:zr ******************** *@bt.com ...

"Bartholomew Simpson" <12**********@terrace.comwrote in message
news:zr*********************@bt.com...

>我需要存储两个浮点值(每个值需要较少的16位存储空间),双数据类型。


任何人都可以给我一些宏来回复/存储双倍的值吗?


/>

STORE_LOWWORD(存储,值)

GET_LOWWORD(存储)/ *返回值* /


STORE_HIGHWORD(存储,价值)

GET_HIGHWORD(存储)/ *返回值* /
>I need to store two float values (each of which requires less 16 bit
storage), in a double data type.

Can anyone give me some macros to retrive/store values in the double ?

something along the lines of

STORE_LOWWORD(storage, value)
GET_LOWWORD(storage) /* returns value */
STORE_HIGHWORD(storage, value)
GET_HIGHWORD(storage) /* returns value */



#define STORE_LOWORD(存储,值)(((float *) & storage)[1] = value)

#define GET_LOWORD(存储)((float *)& storage)[1]


hiword是离开作为练习。如果你是一个小端,则交换名称。

-

免费游戏和编程好东西。
http://www.personal.leeds.ac.uk/~bgy1mm

#define STORE_LOWORD(storage, value) (((float *)&storage)[1] = value)
#define GET_LOWORD(storage) ((float *)&storage)[1]

hiword is left as an exercise. Swap the names if you are a little endian.
--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm


2007年6月25日星期一00:02:11 +0100,Malcolm McLean

< re ******* @ btinternet。 comwrote:
On Mon, 25 Jun 2007 00:02:11 +0100, "Malcolm McLean"
<re*******@btinternet.comwrote:

>
" Bartholomew Simpson" < 12 ********** @ terrace.comwrote in message
新闻:zr ********************* @ bt。 com ...
>
"Bartholomew Simpson" <12**********@terrace.comwrote in message
news:zr*********************@bt.com...

>>我需要在双数据中存储两个浮点值(每个值需要较少的16位存储空间)类型。

任何人都可以给我一些宏来反复/存储双重值吗?

STORE_LOWWORD(存储,值)
GET_LOWWORD(存储)/ *返回值* /

STORE_HIGHWORD(存储,值)
GET_HIGHWORD(存储)/ *返回值* /
>>I need to store two float values (each of which requires less 16 bit
storage), in a double data type.

Can anyone give me some macros to retrive/store values in the double ?

something along the lines of

STORE_LOWWORD(storage, value)
GET_LOWWORD(storage) /* returns value */
STORE_HIGHWORD(storage, value)
GET_HIGHWORD(storage) /* returns value */


#define STORE_LOWORD(存储,值)(((float *)& storage)[1] = value)
#define GET_LOWORD(存储)((float *)& storage)[ 1]

hiword留作练习。如果你是一个小端,交换名称。


#define STORE_LOWORD(storage, value) (((float *)&storage)[1] = value)
#define GET_LOWORD(storage) ((float *)&storage)[1]

hiword is left as an exercise. Swap the names if you are a little endian.



是否有保证双重格式正确对齐

浮点数?

删除del for电子邮件

Is there any guarantee that a double will be properly aligned for a
float?
Remove del for email


这篇关于比特缠绕/操纵问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆