Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13921

Python:how to convert the bytestring to a numeric value

$
0
0

The byte string I read from the ExtensionObject node on the opcua server side isbytestrings how do I convert it to a decimal, this is the result of parsing one of the bytestrings according to the struct module in python.one of theseresultThis is obviously wrong, what am I supposed to do about it, the data I got was something like thisenter image description hereThis is my code:

import struct# Example byte string containing double valuesbyte_string = b'\x84^\x05\x00\x00\xf7\n\x19\n\....'# Determine the size of a double in bytesdouble_size = struct.calcsize('!d')# Calculate the number of double values in the byte stringnum_values = len(byte_string) // double_size# Loop through the byte string and unpack double valuesfor i in range(num_values):    # Calculate the offset for the current double value    offset = i * double_size    # Unpack the double value from the byte string    double_value = struct.unpack_from('!d', byte_string, offset)[0]    print(double_value)

If someone has advices,thank you inadvance.


Viewing all articles
Browse latest Browse all 13921

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>