Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion backend/classification/parser/sd_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

ROWS_TO_SKIP = 2

SIGNED_BIT = int("800000", 16)
SIGNED_BIT_2 = 2 * SIGNED_BIT


def _hexstr_to_int(hexstr):
"""Converts a two complement hexadecimal value in a string to a signed float
Expand All @@ -14,7 +17,8 @@ def _hexstr_to_int(hexstr):
Returns:
- decimal value
"""
return int.from_bytes(bytes.fromhex(hexstr), byteorder='big', signed=True)
raw_int = int(hexstr, 16)
return raw_int - SIGNED_BIT_2 if raw_int >= SIGNED_BIT else raw_int


def parse_sd_file(file):
Expand Down