drf_plot.py 文件源码

python
阅读 35 收藏 0 点赞 0 评论 0

项目:digital_rf 作者: MITHaystack 项目源码 文件源码
def hex2vec(h, ell):
    """hex2vec(h, ell) generates sign vector of length ell from the hex string h.
    ell must be <= 4*len(h) (excluding the optional leading "0x")
    """

    if h[0:2] in ['0x', '0X']:
        h = h[2:]

    nybble = numpy.array([
        [0, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0], [0, 0, 1, 1],
        [0, 1, 0, 0], [0, 1, 0, 1], [
            0, 1, 1, 0], [0, 1, 1, 1],
        [1, 0, 0, 0], [1, 0, 0, 1], [
            1, 0, 1, 0], [1, 0, 1, 1],
        [1, 1, 0, 0], [1, 1, 0, 1], [1, 1, 1, 0], [1, 1, 1, 1]])

    vec = numpy.ravel(numpy.array([nybble[int(x, 16)] for x in h]))

    if len(vec) < ell:
        raise ValueError('hex string too short')
    return vec[len(vec) - ell:]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号