创建C / C 10位数据类型++ [英] Create a 10-bit data type in C/C++

查看:219
本文介绍了创建C / C 10位数据类型++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以创建一个10位数据类型?我可以使用 uint16_t uint32_t的等等,但是如果我想使用什么 uint10_t uint12_t ?这可能吗?

Can create a 10 bit data type? I can use uint16_t, uint32_t, and so forth, but what if I want to use uint10_t or uint12_t? Is this possible?

推荐答案

您不能有一个类型,其大小是不是字节的整数倍 - 因此创建一个10位的数据类型是一个不可取。

You can't have a type whose size isn't a multiple of bytes - so creating a 10-bit datatype is a nonstarter.

您虽然可以创建一个类型,再包含10位presents实体:无论是使用和std :: bitset小于10> 或使用一个10位的位域在16位类型:

You can create a type which represents entities that contain 10 bits though: whether using std::bitset<10> or using a 10-bit bitfield in a 16-bit type:

struct uint10_t {
    uint16_t value : 10;
    uint16_t _     : 6;
};

在这两种情况下,该类型本身会比10比特大。所以,你将无法创建的其中8个阵列,以适应10个字节,例如。

In both cases, the type itself will be larger than 10 bits. So you wouldn't be able to create an array of 8 of them to fit into 10 bytes, for instance.

这篇关于创建C / C 10位数据类型++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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