How can I convert from int to hex

前端 未结 6 2038
你的背包
你的背包 2020-12-14 15:53

I want to convert from int to hex in Golang. In strconv, there is a method that converts strings to hex. Is there a similar method to get a hex string from an int?

6条回答
  •  醉话见心
    2020-12-14 16:36

    E.g. if its uint32, you can convert it to HEX as seen below =>

        var p uint32
        p = 4278190335
        r := p >> 24 & 0xFF
        g := p >> 16 & 0xFF
        b := p >> 8 & 0xFF
        fmt.Println(r, g, b)//255 0 0
    
    

    DEMO

    you can also check this online tool for ref. https://cryptii.com/pipes/integer-encoder

提交回复
热议问题