Skip to content

Commit

Permalink
Added merge bytes test
Browse files Browse the repository at this point in the history
  • Loading branch information
varunrpj committed Oct 23, 2024
1 parent 6f345d7 commit 2a15ec2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
3 changes: 1 addition & 2 deletions dbw/test/test_byte_split.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# This test aims to check the byte split function which splits a given 2-byte (16-bit) value into 2 separate bytes (8 bits each).

for i in range(8):
Expand All @@ -12,5 +11,5 @@

print("High byte: ", "{0:b}".format(byte_list[1]), "{0:x}".format(byte_list[1]))
print("Low byte: " , "{0:b}".format(byte_list[0]), "{0:x}".format(byte_list[0]))

print()
28 changes: 28 additions & 0 deletions dbw/test/test_merge_bytes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This test aims to check the merge bytes function which takes in a high byte and low byte and merges them.

for i in range(8):
num1 = int(255/7*i)
num2 = 255-num1

print("num1 in hexadecimal: ", format(num1, 'x'))
print("num2 in hexadecimal: ", format(num2, 'x'))

print("num1 in binary: ", format(num1, 'b'))
print("num2 in binary: ", format(num2, 'b'))

num1_merge = num1*2**8 + 0xFF
num2_merge = 0xFF00 + num2

merged = num1_merge & num2_merge

print("merged number: ", format(merged, 'x'))
print()


def merge_bytes(high_byte, low_byte):
high = high_byte*2**8 + 0xFF
low = 0xFF00 + low_byte

merged = high & low

return merged

0 comments on commit 2a15ec2

Please sign in to comment.