Skip to content

Commit

Permalink
feat: add binary package
Browse files Browse the repository at this point in the history
  • Loading branch information
WGrape committed May 30, 2023
1 parent aeef86a commit 765cbbf
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 19 deletions.
31 changes: 16 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,20 @@ Since this project consists of individual ```package```, there is almost no code

## Package list

| package | description | api |
|-----------------|----------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------|
| safego | Package safego provides a series of security behaviors. | [document](https://pkg.go.dev/github.com/WGrape/golib/safego) |
| permutation | Package permutation provides many algorithms about permutation and combination. | [document](https://pkg.go.dev/github.com/WGrape/golib/permutation) |
| http | The http package provides efficient and high-performance network operations. | [document](https://pkg.go.dev/github.com/WGrape/golib/http) |
| package | description | api |
|-----------------|---------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------|
| safego | Package safego provides a series of security behaviors. | [document](https://pkg.go.dev/github.com/WGrape/golib/safego) |
| permutation | Package permutation provides many algorithms about permutation and combination. | [document](https://pkg.go.dev/github.com/WGrape/golib/permutation) |
| http | The http package provides efficient and high-performance network operations. | [document](https://pkg.go.dev/github.com/WGrape/golib/http) |
| redis | Package redis provides advanced operations, such as ```Cache Penetration, Cache Breakdown, Cache Avalanche```. | [document](https://pkg.go.dev/github.com/WGrape/golib/redis) |
| desensitization | Package desensitization provides data desensitization support. | [document](https://pkg.go.dev/github.com/WGrape/golib/desensitization) |
| time | Package time provides functionality for measuring and displaying time more efficiently. | [document](https://pkg.go.dev/github.com/WGrape/golib/time) |
| array | Package array provides functionality for measuring and displaying array more efficiently. | [document](https://pkg.go.dev/github.com/WGrape/golib/array) |
| convert | Package convert provides simpler conversion between int, float, and string. | [document](https://pkg.go.dev/github.com/WGrape/golib/convert) |
| set | Package set provides simpler set operations. | [document](https://pkg.go.dev/github.com/WGrape/golib/set) |
| math | Package math provides simpler math operations. | [document](https://pkg.go.dev/github.com/WGrape/golib/math) |
| system | Package system provides an interface to interact with the linux system. | [document](https://pkg.go.dev/github.com/WGrape/golib/system) |
| string | Package string provides an interface to process string in the simpler way. | [document](https://pkg.go.dev/github.com/WGrape/golib/string) |
| slice | Package slice provides an interface to process slice in the simpler way. | [document](https://pkg.go.dev/github.com/WGrape/golib/slice) |
| frontend | Package frontend provides an interface to work with front-end colleagues in the simpler way. | [document](https://pkg.go.dev/github.com/WGrape/golib/frontend) |
| desensitization | Package desensitization provides data desensitization support. | [document](https://pkg.go.dev/github.com/WGrape/golib/desensitization) |
| time | Package time provides functionality for measuring and displaying time more efficiently. | [document](https://pkg.go.dev/github.com/WGrape/golib/time) |
| array | Package array provides functionality for measuring and displaying array more efficiently. | [document](https://pkg.go.dev/github.com/WGrape/golib/array) |
| binary | Package binary provides some operations of binary number and decimal number. | [document](https://pkg.go.dev/github.com/WGrape/golib/binary) |
| convert | Package convert provides simpler conversion between int, float, and string. | [document](https://pkg.go.dev/github.com/WGrape/golib/convert) |
| set | Package set provides simpler set operations. | [document](https://pkg.go.dev/github.com/WGrape/golib/set) |
| math | Package math provides simpler math operations. | [document](https://pkg.go.dev/github.com/WGrape/golib/math) |
| system | Package system provides an interface to interact with the linux system. | [document](https://pkg.go.dev/github.com/WGrape/golib/system) |
| string | Package string provides an interface to process string in the simpler way. | [document](https://pkg.go.dev/github.com/WGrape/golib/string) |
| slice | Package slice provides an interface to process slice in the simpler way. | [document](https://pkg.go.dev/github.com/WGrape/golib/slice) |
| frontend | Package frontend provides an interface to work with front-end colleagues in the simpler way. | [document](https://pkg.go.dev/github.com/WGrape/golib/frontend) |
9 changes: 5 additions & 4 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,11 @@ func (strategy *UseStrategy) getCombinationList(propertyList []string) []string
| desensitization | desensitization包提供数据脱敏支持 | [文档](https://pkg.go.dev/github.com/WGrape/golib/desensitization) |
| time | time包提供了更高效的时间处理操作 | [文档](https://pkg.go.dev/github.com/WGrape/golib/time) |
| array | array包提供了更高效的数组操作 | [文档](https://pkg.go.dev/github.com/WGrape/golib/array) |
| binary | binary包提供了更高效的十进制数字和二进制相关的操作. | [document](https://pkg.go.dev/github.com/WGrape/golib/binary) |
| convert | convert包提供了更加简单的整型、浮点型、字符串类型之间的转换 | [文档](https://pkg.go.dev/github.com/WGrape/golib/convert) |
| set | set包提供了更加简单的集合运算操作 | [文档](https://pkg.go.dev/github.com/WGrape/golib/set) |
| math | math包提供了更加简单的关于数学计算相关的操作 | [文档](https://pkg.go.dev/github.com/WGrape/golib/math) |
| system | system包提供了与Linux交互的接口 | [文档](https://pkg.go.dev/github.com/WGrape/golib/system) |
| string | string包提供了更简单的String处理接口 | [文档](https://pkg.go.dev/github.com/WGrape/golib/string) |
| slice | slice包提供了更简单的Slice处理接口 | [文档](https://pkg.go.dev/github.com/WGrape/golib/slice) |
| frontend | frontend包提供了与前端交互工作时更简单的接口 | [文档](https://pkg.go.dev/github.com/WGrape/golib/frontend) |
| system | system包提供了与Linux交互的接口 | [文档](https://pkg.go.dev/github.com/WGrape/golib/system) |
| string | string包提供了更简单的String处理接口 | [文档](https://pkg.go.dev/github.com/WGrape/golib/string) |
| slice | slice包提供了更简单的Slice处理接口 | [文档](https://pkg.go.dev/github.com/WGrape/golib/slice) |
| frontend | frontend包提供了与前端交互工作时更简单的接口 | [文档](https://pkg.go.dev/github.com/WGrape/golib/frontend) |
18 changes: 18 additions & 0 deletions binary/binary.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2022 The golib Authors. All rights reserved.
// Use of this source code is governed by a BSD-style(https://en.wikipedia.org/wiki/BSD_licenses)
// license that can be found in the LICENSE file.

// Package binary provides some operations of binary number and decimal number.
package binary

// DecimalNumberToBinary Return a binary array.
func DecimalNumberToBinary(num int) []int {
var binary []int

for num != 0 {
binary = append(binary, num%2)
num = num / 2
}

return binary
}
14 changes: 14 additions & 0 deletions binary/binary_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package binary

import (
"reflect"
"testing"
)

// TestDecimalNumberToBinary Test the function DecimalNumberToBinary
func TestDecimalNumberToBinary(t *testing.T) {
if reflect.DeepEqual(DecimalNumberToBinary(4), []int{1, 0, 0}) {
t.Fail()
return
}
}

0 comments on commit 765cbbf

Please sign in to comment.