From 2fa470611eeae86d705c404692129d092497d174 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E6=B5=B7=E6=B4=8B?= <517573303@qq.com> Date: Tue, 28 Dec 2021 12:35:15 +0000 Subject: [PATCH] =?UTF-8?q?add=20day1/=E4=BD=9C=E4=B8=9A/GO7031-=E6=9D=8E?= =?UTF-8?q?=E6=B5=B7=E8=B6=85.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...7031-\346\235\216\346\265\267\350\266\205" | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 "day1/\344\275\234\344\270\232/GO7031-\346\235\216\346\265\267\350\266\205" diff --git "a/day1/\344\275\234\344\270\232/GO7031-\346\235\216\346\265\267\350\266\205" "b/day1/\344\275\234\344\270\232/GO7031-\346\235\216\346\265\267\350\266\205" new file mode 100644 index 0000000..f0070a7 --- /dev/null +++ "b/day1/\344\275\234\344\270\232/GO7031-\346\235\216\346\265\267\350\266\205" @@ -0,0 +1,31 @@ +package main + +import ( + "fmt" + "math" + "strings" +) + +func BinaryFormat(n int32) string { + a := uint32(n) + fmt.Println(a) + sb := strings.Builder{} + c := uint32(math.Pow(2, 31)) + fmt.Println(c) + for i := 0; i < 32; i++ { + if a&c != 0 { + sb.WriteString("1") + } else { + sb.WriteString("0") + } + c >>= 1 + } + return sb.String() +} +func main() { + fmt.Println(BinaryFormat(0)) + fmt.Println(BinaryFormat(1)) + fmt.Println(BinaryFormat(-1)) + fmt.Println(BinaryFormat(260)) + fmt.Println(BinaryFormat(-260)) +} \ No newline at end of file -- Gitee