Skip to content

Instantly share code, notes, and snippets.

@nmarley
Created July 12, 2018 04:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nmarley/31c25895fcd7af782eba968909c7da40 to your computer and use it in GitHub Desktop.
Save nmarley/31c25895fcd7af782eba968909c7da40 to your computer and use it in GitHub Desktop.
Split 32-bit signed tx version field into version and type
package main
import "fmt"
func main() {
// set old (signed 32-bit) version
// var versionOld int32 = -987005808
var versionOld int32 = 2
// split into version and type fields (`type` is a reserved keyword in Go)
var version = int16(versionOld & 0xffff)
var ntype = int16((versionOld >> 16) & 0xffff)
// print old & new
fmt.Println("versionOld =", versionOld)
fmt.Println("version =", version)
fmt.Println("ntype =", ntype)
}
// this->nVersion = (int16_t) (n32bitVersion & 0xffff);
// this->nType = (int16_t) ((n32bitVersion >> 16) & 0xffff);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment