Skip to content

Instantly share code, notes, and snippets.

@j0shua
Created October 15, 2018 23:39
Show Gist options
  • Save j0shua/083706332fe25e4728d730b9c9e7a43f to your computer and use it in GitHub Desktop.
Save j0shua/083706332fe25e4728d730b9c9e7a43f to your computer and use it in GitHub Desktop.
parse first 16 chars from hash (string) to int64
package main
import (
"strconv"
"fmt"
"reflect"
)
func main() {
// Use the max value for signed 64 integer. http://golang.org/pkg/builtin/#int64
var hash string = "0c821f675f132d790b3f25e79da739a7"
var short = hash[0:16]
fmt.Printf("short is %s\n", short)
i, err := strconv.ParseInt(short, 16, 64)
if err != nil {
panic(err)
}
fmt.Printf("%v with type %s!\n", i, reflect.TypeOf(i))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment