加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

【比特币】大数的紧凑表示法

发布时间:2020-12-14 03:02:56 所属栏目:大数据 来源:网络整理
导读:// The "compact" format is a representation of a whole // number N using an unsigned 32bit number similar to a // floating point format. // The most significant 8 bits are the unsigned exponent of base 256. // This exponent can be thought
    // The "compact" format is a representation of a whole
    // number N using an unsigned 32bit number similar to a
    // floating point format.
    // The most significant 8 bits are the unsigned exponent of base 256.
    // This exponent can be thought of as "number of bytes of N".
    // The lower 23 bits are the mantissa.
    // Bit number 24 (0x800000) represents the sign of N.
    // N = (-1^sign) * mantissa * 256^(exponent-3)
    //
    // Satoshi's original implementation used BN_bn2mpi() and BN_mpi2bn().
    // MPI uses the most significant bit of the first byte as sign.
    // Thus 0x1234560000 is compact (0x05123456)
    // and  0xc0de000000 is compact (0x0600c0de)
    // (0x05c0de00) would be -0x40de000000
    //
    // Bitcoin only uses this "compact" format for encoding difficulty
    // targets,which are unsigned 256bit quantities.  Thus,all the
    // complexities of the sign bit and using base 256 are probably an
    // implementation accident.


备注:


1) MSB 多字节整数的高字节位

>表示的数字大,更有意义的字节,知道这个字节,就大概知道了这个整数的大概范围,比如0x10aa,知道10,大概知道这个数是4k以上的)


2) LSB 多字节整数的地字节位

>表示的数字小,不是很有意义的字节,知道这个字节,还是不知道这个整数到底有多大,比如0x10aa,知道aa,还是不知道这个数字有多大)


3) Big-endian: ? 一个大整数m的MSB存储于内存的低地址,而这个m的LSB存储于高地址

>因为存储于低地址的MSB字节在网络传输的时候先传送,所以叫big-endian,从大头开始)


4) Little-endian:一个大整数m的LSB存储于内存的低地址,而这个m的MSB存储于高地址

>因为存储于低地址的LSB字节在网络传输的时候先传送,所以叫little-endian,从小头开始)



参考:

http://zh.wikipedia.org/wiki/%E5%AD%97%E8%8A%82%E5%BA%8F

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读