内容简介:以之前的bits:181B7B74为例子
比特币目标hash计算过程
以之前的bits:181B7B74为例子
func main(){ bits,_:= hex.DecodeString("181B7B74") fmt.Printf("%x",CalculateTargetFast(bits)) } //18 1B7B74 func CalculateTargetFast(bits []byte) []byte{ var result []byte //第一个字节 计算指数 exponent := bits[:1] fmt.Printf("%x\n",exponent) //计算后面3个字节 系数 coeffient:= bits[1:] fmt.Printf("%x\n",coeffient) //将字节,他的16进制为"18" 转化为了string "18" str:= hex.EncodeToString(exponent) //"18" fmt.Printf("str=%s\n",str) //将字符串18转化为了10进制int64 24 exp,_:=strconv.ParseInt(str,16,8) fmt.Printf("exp=%d\n",exp) //拼接,计算出目标hash result = append(bytes.Repeat([]byte{0x00},32-int(exp)),coeffient...) result = append(result,bytes.Repeat([]byte{0x00},32-len(result))...) return result }
-
本文链接: https://dreamerjonson.com/2018/12/12/golang-44-blockchain-targetHash/
-
版权声明: 本博客所有文章除特别声明外,均采用 CC BY 4.0 CN协议 许可协议。转载请注明出处!
以上所述就是小编给大家介绍的《golang[44]-blockchain-targetHash》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。