gcc 7.3 128位无符号整数运算 [英] gcc 7.3 128-bit unsigned integer operation

查看:261
本文介绍了gcc 7.3 128位无符号整数运算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对128位整数的用法感到困惑. 请查看测试代码:

I'm confused with the usage of 128-bit integer. Please look at the test code:

uint128_t test_data = 0x00000000FFFFFFFF0101010101010101;
uint64_t test_data_h = test_data  >> 64;
uint64_t test_data_l = test_data ;
printf("test_data 0x %016llx %016llx\n", test_data_h, test_data_l);

我希望test_data_h为0x00000000FFFFFFFFFF,但结果是:

I expect the test_data_h to be 0x00000000FFFFFFFF, but the result is :

test data 0x 0000000000000000 0101010101010101

这是为什么?

推荐答案

许多编译器不支持128位常量.

Many compilers do not support 128 bit constants.

相反

// uint128_t test_data = 0x00000000FFFFFFFF0101010101010101;
uint128_t test_data = (((uint128_t) 0x00000000FFFFFFFF) << 64) | 0x0101010101010101;

提示:启用所有编译器警告.

Tip: enable all compiler warnings.

这篇关于gcc 7.3 128位无符号整数运算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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