小编Mat*_*cci的帖子

C努力将无符号整数打包到uint64_t中

我收到了一个数据集合,我需要将它打包成一个uint64_t值,在下面的示例中采用"weatherlog_t"类型的形式

我不允许使用算术运算符(+,++, - , - ,*,%,/,...),但我可以使用按位运算符(&,|,^,<<,>> ,〜)和逻辑运算符(!,=, - ,!=,&&和||)

但是我确实有预定义的add()和sub()函数来处理按位加法和减法,它们在下面的例子中使用.这些已经过测试,我很确定它们的工作达到了这里所需的程度.

根据说明,64位值必须按如下方式排列:

    /* - year :: 6 bits -- stored as the number of years since the year 2000.
    - month :: 4 bits
    - day :: 5 bits
    - zip_code :: 16 bits
    - high_temp :: in degrees Fahrenheit, stored as an 8-bit signed integer
    - low_temp :: in degrees Fahrenheit, stored as 8-bit signed integer
    - precipitation :: in mm. stored as a 10-bit unsigned integer.
    - average_wind_speed :: …
Run Code Online (Sandbox Code Playgroud)

c math bit-manipulation packing uint64

1
推荐指数
1
解决办法
131
查看次数

标签 统计

bit-manipulation ×1

c ×1

math ×1

packing ×1

uint64 ×1