C中是否有通用的方法使数字大于64位或小于8位? [英] Is there a general way in C to make a number greater than 64 bits or smaller than 8 bits?

查看:175
本文介绍了C中是否有通用的方法使数字大于64位或小于8位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


首先,我知道我要做的事情可能超出了C标准。

First of all, I am aware that what I am trying to do might be outside the C standard.

我想知道是否可以制作 uint4_t / int4_t uint128_t / int128_t 输入C。

I'd like to know if it is possible to make a uint4_t/int4_t or uint128_t/int128_t type in C.

我知道我可以做这是使用位移和复杂函数,但是我可以在没有这些的情况下进行吗?

I know I could do this using bitshifts and complex functions, but can I do it without those?

推荐答案

您可以在结构中使用位域来获取字段比uint8_t窄,但是,它们存储的基本数据类型不会更小。

You can use bitfields within a structure to get fields narrower than a uint8_t, but, the base datatype they're stored in will not be any smaller.

struct SmallInt
{
   unsigned int a : 4;
};

将为您提供一个名为4位宽的成员的结构。

will give you a structure with a member called a that is 4 bits wide.

这篇关于C中是否有通用的方法使数字大于64位或小于8位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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