便携式有符号/无符号字节映射,C ++ [英] portable signed/unsigned byte cast,C++
问题描述
我使用签名到无符号字节(int8_t)转换来压缩字节。
I am using signed to unsigned byte(int8_t) cast to pack byts.
uint32_t(uint8_t(byte)) << n
这在Intel Linux上使用GCC。是可移植的其他平台/编译器,例如PowerPC?
是有更好的方法吗?使用bitset是不可能的在我的情况。
我通过boost使用stdint
This works using GCC on Intel Linux. Is that portable for other platforms/compilers, for example PowerPC? is there a better way to do it? using bitset is not possible in my case. I am using stdint via boost
推荐答案
如果你使用 boost / cstdint.hpp 从Boost Integer库中,然后是,typedefs是可移植的(跨平台。)
boost / cstdint.hpp
C ++中的C99 stdint.h功能。
If you are using boost/cstdint.hpp
from the Boost Integer library, then yes, the typedefs are portable (cross-platform.) The boost/cstdint.hpp
header is meant to implement C99 stdint.h functionality in C++.
从 Boost文档:
typedef对
有用,写入可移植代码,需要
一定的整数宽度。所有typedef的
都在命名空间中。
The header provides the typedef's useful for writing portable code that requires certain integer widths. All typedef's are in namespace boost.
这篇关于便携式有符号/无符号字节映射,C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!