Skip to content

Instantly share code, notes, and snippets.

@joaofnds
Created November 14, 2018 03:21
Show Gist options
  • Select an option

  • Save joaofnds/ea9c5b329fdc245010ed23201e1195d0 to your computer and use it in GitHub Desktop.

Select an option

Save joaofnds/ea9c5b329fdc245010ed23201e1195d0 to your computer and use it in GitHub Desktop.
package main
import (
"bufio"
"fmt"
"io"
"log"
"os"
)
func main() {
f, err := os.Open("print_file_as_binary.go")
if err != nil {
log.Fatal("Error while trying to open file", err)
}
defer f.Close()
r := bufio.NewReader(f)
b, err := r.ReadByte()
for ; err == nil; b, err = r.ReadByte() {
fmt.Printf("%08b", b)
}
println()
if err != io.EOF {
log.Fatal("unexpected error while reading bytes", err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment