Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinBlandy committed Sep 20, 2024
1 parent 5bc8aea commit fd62d47
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 15 deletions.
8 changes: 8 additions & 0 deletions Go/lib/math/rand.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ rand
func (r *Rand) Read(p []byte) (n int, err error)
func (r *Rand) Seed(seed int64)
func (r *Rand) Shuffle(n int, swap func(i, j int))
* 洗牌n 表示元素长度swap 为元素交换方法
arr := []int{1, 2, 3, 4}
rand.Shuffle(len(arr), func(i, j int) {
// 交换元素位置
arr[i], arr[j] = arr[j], arr[i]
})
fmt.Println(arr) // [4 1 3 2]

func (r *Rand) Uint32() uint32
func (r *Rand) Uint64() uint64

Expand Down
4 changes: 2 additions & 2 deletions Go/练习/基于Redis的可靠MQ.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ func ReQueue(ctx context.Context, count int) (int, error) {
return items, nil
}

// QueueLen 待消费队列长度
func QueueLen(ctx context.Context) (int, error) {
// Len 待消费队列长度
func Len(ctx context.Context) (int, error) {
conn := rdb.Conn()
size, err := conn.LLen(ctx, keyQueue).Result()
return int(size), err
Expand Down
48 changes: 35 additions & 13 deletions Java/java-二进制.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,28 +140,50 @@
# 给定一个负数的二进制表示要想知道它的十进制值可以采用相同的补码运算

10010010
* 已知是 1 开头表示的值是一个负数
* 取反01101101
* 加一00000001
* 结果01101110

01101110 十进制值为: 110, 所以原值就是 -110


* 对负数的补码表示做补码运算就可以得到其对应正数的原码正如十进制运算中负负得正一样
* 原因是只有这种形式计算机才能实现正确的加减法计算机其实只能做加法1 - 1 其实是1+(-1)

* 1-1 其实是 1 + (-1)。如果用原码表示:
1 00000001
-1 10000001
+ ------------------
-2 10000010
* 对负数的补码表示做补码运算就可以得到其对应正数的原码正如十进制运算中负负得正一样
* 原因是只有这种形式计算机才能实现正确的加减法计算机其实只能做加法1 - 1 其实是1+(-1)

* 1-1 其实是 1 + (-1)。如果用原码表示:
1 00000001
-1 10000001
+ ------------------
-2 10000010

* 负数以补码性质正确
1 00000001
-1 11111111 //
+ ------------------
0 00000000

* 负数以补码性质正确
1 00000001
-1 11111111 //
+ ------------------
0 00000000
# 例如计算 3 - 5
3
* 原码00000011
+

(-5)
* 原码00000101
* 取反11111010
* 加一11111011

=
00000011
11111011
--------
11111110

* 最高位是1表示结果是负数
* 取反00000001
* 加一00000010
* 结果为 2由于是负数则结果为 -2

-----------------------
小数
Expand Down

0 comments on commit fd62d47

Please sign in to comment.