Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

64 bit float and integer reading in linux #56

Open
tadzil opened this issue Feb 14, 2022 · 0 comments
Open

64 bit float and integer reading in linux #56

tadzil opened this issue Feb 14, 2022 · 0 comments

Comments

@tadzil
Copy link

tadzil commented Feb 14, 2022

As there is inaccuracy in reading float values, I'm using some bash commands to get right value in different byte orders and endiannesses.
Maybe someone else will find this usefull:

#32 bit float:
#BIG Endian
/usr/local/bin/mbpoll -t4:hex -c2 -0 -B -1 -q -r 10 127.0.0.1 -p 1502 | awk 'FNR >= 2 {print $2}' | awk '{sub(/^0x/,""); print}' | tr -d "\n" | python3 -c 'import struct; print(struct.unpack("!f", bytes.fromhex(input()))[0])'

#LITTLE Endian
/usr/local/bin/mbpoll -t4:hex -c2 -0 -B -1 -q -r 10 127.0.0.1 -p 1502 | awk 'FNR >= 2 {print $2}' | awk '{sub(/^0x/,""); print}' | fold -w2 | tac | tr -d "\n" | python3 -c 'import struct; print(struct.unpack("!f", bytes.fromhex(input()))[0])'

#BIG Endian BYTE Swapped
/usr/local/bin/mbpoll -t4:hex -c2 -0 -B -1 -q -r 10 127.0.0.1 -p 1502 | awk 'FNR >= 2 {print $2}' | awk '{sub(/^0x/,""); print}' | fold -w4 | tac | fold -w2 | tac | tr -d "\n" | python3 -c 'import struct; print(struct.unpack("!f", bytes.fromhex(input()))[0])'

#LITTLE Endian BYTE Swapped
/usr/local/bin/mbpoll -t4:hex -c2 -0 -B -1 -q -r 10 127.0.0.1 -p 1502 | awk 'FNR >= 2 {print $2}' | awk '{sub(/^0x/,""); print}' | fold -w4 | tac | tr -d "\n" | python3 -c 'import struct; print(struct.unpack("!f", bytes.fromhex(input()))[0])'

#64 bit float:
#BIG Endian
/usr/local/bin/mbpoll -t4:hex -c4 -0 -B -1 -q -r 10 127.0.0.1 -p 1502 | awk 'FNR >= 2 {print $2}' | awk '{sub(/^0x/,""); print}' | tr -d "\n" | python3 -c 'import struct; print(struct.unpack("!d", bytes.fromhex(input()))[0])'

#LITTLE Endian
/usr/local/bin/mbpoll -t4:hex -c4 -0 -B -1 -q -r 10 127.0.0.1 -p 1502 | awk 'FNR >= 2 {print $2}' | awk '{sub(/^0x/,""); print}' | fold -w2 | tac | tr -d "\n" | python3 -c 'import struct; print(struct.unpack("!d", bytes.fromhex(input()))[0])'

#BIG Endian BYTE Swapped
/usr/local/bin/mbpoll -t4:hex -c4 -0 -B -1 -q -r 10 127.0.0.1 -p 1502 | awk 'FNR >= 2 {print $2}' | awk '{sub(/^0x/,""); print}' | fold -w4 | tac | fold -w2 | tac | tr -d "\n" | python3 -c 'import struct; print(struct.unpack("!d", bytes.fromhex(input()))[0])'

#LITTLE Endian BYTE Swapped
/usr/local/bin/mbpoll -t4:hex -c4 -0 -B -1 -q -r 10 127.0.0.1 -p 1502 | awk 'FNR >= 2 {print $2}' | awk '{sub(/^0x/,""); print}' | fold -w4 | tac | tr -d "\n" | python3 -c 'import struct; print(struct.unpack("!d", bytes.fromhex(input()))[0])'


##32 bit integer:
#commands are the same, as for 32 bit float, except:
#for signed 32bit integer, use "l" in python unpack format - "...struct.unpack("!l",...";
#for unsigned 32bit integer, use "L" in python unpack format - "...struct.unpack("!L",...".

##64 bit integer:
#commands are the same, as for 64 bit float, except:
#for signed 64bit integer, use "q" in python unpack format - "...struct.unpack("!q",...";
#for unsigned 64bit integer, use "Q" in python unpack format - "...struct.unpack("!Q",...".

mbpoll_32_64bit_tests.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant