From 0f2b8ac3a02b6a364519134d1881fe1854d56c09 Mon Sep 17 00:00:00 2001 From: q191201771 <191201771@qq.com> Date: Mon, 4 May 2020 11:29:03 +0800 Subject: [PATCH] test math/bits --- playground/p13/p13.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 playground/p13/p13.go diff --git a/playground/p13/p13.go b/playground/p13/p13.go new file mode 100644 index 0000000..1d10b7e --- /dev/null +++ b/playground/p13/p13.go @@ -0,0 +1,35 @@ +// Copyright 2020, Chef. All rights reserved. +// https://github.com/q191201771/naza +// +// Use of this source code is governed by a MIT-style license +// that can be found in the License file. +// +// Author: Chef (191201771@qq.com) + +package main + +import ( + "fmt" + "math/bits" +) + +func main() { + var a uint32 + a = 1 + fmt.Printf("%032b\n", a) + fmt.Printf("%032b\n", bits.ReverseBytes32(a)) + a = a << 8 + fmt.Printf("%032b\n", a) + fmt.Printf("%032b\n", bits.ReverseBytes32(a)) + + var b uint64 + b = 1 + fmt.Printf("%064b\n", b) + fmt.Printf("%064b\n", bits.ReverseBytes64(b)) + b = b << 8 + fmt.Printf("%064b\n", b) + fmt.Printf("%064b\n", bits.ReverseBytes64(b)) + b = b << 8 + fmt.Printf("%064b\n", b) + fmt.Printf("%064b\n", bits.ReverseBytes64(b)) +}