在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
发布评论