dongpang1898 2016-12-08 03:47
浏览 211
已采纳

遍历所有可能的字节

So I'm trying to test a function against every possible byte, that is 0 to 255 possibilities. How do I iterate over all possible bytes? i've

I've tried

 for i := 0; i < 256; i++ {
      fmt.Println(byte(i)) // prints a number 0-255
      fmt.Println(byte{i}) // crashes
 }
  • 写回答

4条回答 默认 最新

  • douzao2590 2016-12-08 03:58
    关注

    If you need to ensure that "i" variable is a byte (i.e. uint8), then you can do:

    for i := byte(0); i < 255; i++ {
        fmt.Println(i)
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?