如何获取以 16 为基数的数学/大 Int 变量的日志。
任何帮助都会很棒,因为我是 Go 的新手并且来自 Python 和 C 环境
s := "c6d86e5a2cb4bc532361c2d4940f0b1a0138066e25d65c1c530d080b11f8ca24" // Hex value
i := new(big.Int)
i.SetString(s, 16) // hex value to Big Int
// how to get the log with base 16 for a math/big Int variable.
它在 python 中是如何工作的
import math
a = 0xc6d86e5a2cb4bc532361c2d4940f0b1a0138066e25d65c1c530d080b11f8ca24
a>> 89940344608680314083397671686667731393131665861770496634981932531495305005604L
math.log(a)/math.log(16.0)
答案原来是63.908875905794794
最佳答案
对于 log16 和 hex 输入有特定的方法,无需长时间的算术运算。
要获得整数(底数)结果,只需计算十六进制数字。在这种情况下有 63 位数字,所以你有
FloorLog16 = 63
现在获取前 8 个数字(更多以提高精度)
b = 0xc6d86e5a
得到log16
p = log(b) / log(16) = 7.908875905775919
使用这个结果的小数部分使对数更精确
fp = p - Floor(p) = 0.908875905775919
log16(0xc6d86e5a2cb4bc532361c2d4940f0b1a0138066e25d65c1c530d080b11f8ca24) =
63 + 0.908875905775919 = 63.908875905775919
注意 12 个精确数字
关于go - 如何在 Golang 中计算 256 位整数的 log16,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52917461/