Go 中的自定义长度位类型?

Custom length bit types in Go?

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

我打算使用 "just enough bits" 来表示变量,并且想要 6 位和 4 位类型。也许是复合 bool 类型?

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

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

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

参考文献:

The Go Programming Language Specification