dousong2967 2016-06-28 23:26
浏览 12
已采纳

前往:如何划分大量数字?

I'm new in Golang and my problem is:

I have two byte arrays of 64 elements each, let's name them "A" and "B". Each of those arrays represent an unsigned integer.

I wish to produce another 64-bytes array "R" representing the result of (A / B).

Any ideas?

// pre-condition: A and B have 64 bytes each
// A and B each represent an unsigned integer
// R = (A / B)

func divideByteArrays(A, B []byte) []byte {
    R := make([]byte, 64)
    // ... do something ...
    return R
}

Thanks in advance!

EDIT:

is it possible to use "math/big" to achieve that goal ?

  • 写回答

1条回答 默认 最新

  • duannue2455 2016-06-29 00:18
    关注

    https://play.golang.org/p/T5R8fB8q60

    package main
    
    import (
        "math/big"
        "fmt"
    )
    
    func divideByteArrays(A, B []byte) []byte {
        var AI, BI, R big.Int
        AI.SetBytes(A)
        BI.SetBytes(B)
        R.Div(&AI, &BI)
        return R.Bytes()
    }
    
    func main() {
        a_array := make([]byte, 64)
        b_array := make([]byte, 64)
    
        for i := 0; i < 64; i++ {
            a_array[i] = 4
            b_array[i] = 2
        }
    
        fmt.Println(divideByteArrays(a_array, b_array))
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)