Go中的自定义长度位类型?(Custom length bit types in Go?)

编程入门 行业动态 更新时间:2024-10-27 20:30:15
Go中的自定义长度位类型?(Custom length bit types in Go?)

在Go中,是否可以定义一个自定义类型,其中包含byte uint uint16或任何其他内置类型提供的位数以外的位数?

我打算使用“足够的位”来表示变量,并希望使用6位和4位类型。 也许复合bool类型?

type fourbit struct{ ones bool twos bool fours bool eights bool }

虽然这种事情非常混乱,但对于n位类型有一个更通用的解决方案会更好。

In Go is it possible to define a custom type with a number of bits other than those offered by byte uint uint16 or any of the other built-in types?

I'm planning on using "just enough bits" to represent variables and wanted a 6-bit and a 4-bit type. Perhaps a composite bool type?

type fourbit struct{ ones bool twos bool fours bool eights bool }

Though this sort of thing is quite messy and it would be nice to have a more general solution for n-bit types.

最满意答案

不是。当前实现中Go类型的最小大小,包括bool类型,是一个字节,。

参考文献:

Go编程语言规范

No. The minimum size of a Go type in current implementations, including type bool, is one byte, .

References:

The Go Programming Language Specification

更多推荐

类型,bool,type,uint,电脑培训,计算机培训,IT培训"/> <meta name="description

本文发布于:2023-08-05 16:31:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1433928.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   长度   类型   Custom   bit

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!