Skip to content

Commit

Permalink
hex
Browse files Browse the repository at this point in the history
  • Loading branch information
Benature committed Oct 24, 2019
1 parent 5bf2d31 commit 5c2246a
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions other/hex2bin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# File Name : hex2bin.py
# Author : Benature
# Create Date: 2019.09.29 周日

# 16进制转2进制
# 计算误码率

import math
import numpy as np

path_r = "../data/normal/receiver_sift.bin"
path_t = "../data/normal/transmitter_sift.bin"

with open(path_r , "rb") as f1:
receiver = f1.read()
with open(path_t , "rb") as f2:
transmitter = f2.read()

def hex2bin(sift):
out = []
for he in sift:
bi = "{:0>8}".format(bin(he)[2:])
bi = np.array(list(bi))
out.append(bi)
return out

sift_r = np.array(hex2bin(receiver))
sift_t = np.array(hex2bin(transmitter))

judge = (sift_r == sift_t)

correct = np.sum(judge)
total = judge.shape[0] * judge.shape[1]

print("误码率:", (total - correct) / total)

0 comments on commit 5c2246a

Please sign in to comment.