Skip to content

进制转换

bash
package main

import (
  "fmt"
  "strconv"
  "time"
)

func main() {
  fmt.Println(time.Now())
  fmt.Println(time.Now().Unix())
  etime := strconv.FormatInt(time.Now().Unix(), 16) //10 yo 16
  fmt.Printf("%v\n", etime)

  var v int64 = 1658854677      //默认10进制
  s2 := strconv.FormatInt(v, 2) // 10 to 2
  fmt.Printf("%v\n", s2)

  s8 := strconv.FormatInt(v, 8) // 10 to 8
  fmt.Printf("%v\n", s8)

  s10 := strconv.FormatInt(v, 10)
  fmt.Printf("%v\n", s10)

  s16 := strconv.FormatInt(v, 16) // 10 to 16
  fmt.Printf("%v\n", s16)

  var sv = "19584c4d" // 16 to 10
  fmt.Println(strconv.ParseInt(sv, 16, 32))
}