Created
November 14, 2018 03:21
-
-
Save joaofnds/ea9c5b329fdc245010ed23201e1195d0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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