Parsing/Representing Bits in Go

10 Sep 2016

Sometimes it's nice to see bits as I play with them. Here's how to parse a string of 64 zeros and ones into a uint64:

  n, err := strconv.ParseUint("0110000000000000000000000000000000000000000000000000000000000000", 2, 64)
  if err != nil {
    log.Fatal(err)
  }

And here's how to print those bits back out:

  fmt.Printf("n == %d == %064b\n", n, n)

Here's the output:

n == 6917529027641081856 == 0110000000000000000000000000000000000000000000000000000000000000