Converting from an integer to its binary representation

前端 未结 7 1361
野的像风
野的像风 2020-12-24 00:09

Has anyone got an idea if there is any inbuilt functionality in Go for converting from any one of the numeric types to its binary number form.

For example, if

7条回答
  •  一向
    一向 (楼主)
    2020-12-24 00:45

    package main
    
    import . "fmt"
    
    func main(){
        Printf("%d == %08b\n",0,0)
        Printf("%d == %08b\n",1,1)
        Printf("%d == %08b\n",2,2)
        Printf("%d == %08b\n",3,3)
        Printf("%d == %08b\n",4,4)
        Printf("%d == %08b\n",5,5)
    }
    

    results in:

    0 == 00000000
    1 == 00000001
    2 == 00000010
    3 == 00000011
    4 == 00000100
    5 == 00000101
    

提交回复
热议问题