doumi9618 2015-10-29 21:59
浏览 102
已采纳

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

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.

  • 写回答

1条回答 默认 最新

  • doushaju4901 2015-10-29 22:27
    关注

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

    References:

    The Go Programming Language Specification

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作