2016-07-17 6 views
-1

Ich habe ein Programm erstellt, das int64 binär konvertiert:Wie konvertiert man Int64 zu Binär und behält führende Nullen in Golang?

package main 

import (
    "fmt" 
    "strconv" 
) 

func main() { 
    n := int64(3) 
    fmt.Println(strconv.FormatInt(n, 2)) 
} 

Und es gibt diesen Wert zurück:

11 

Wie kann ich die führenden Nullen in der Antwort halten?

Vielen Dank im Voraus!

+2

Mögliche Duplikat [Golang: Wie packen Sie beim Drucken eine Zahl mit Nullen?] (http://stackoverflow.com/questions/25 637440/golang-how-to-pad-a-number-with-nullen-when-printing) – coredump

+0

Siehe https://play.golang.org/p/lS0DoMLth6 – coredump

Antwort

Verwandte Themen