How to read fixed point numbers in python

I would like to read an 8-bit number, which is included in 2 fix8_7 additions (8-bit number and 7-bit binary point). How can I do this in Python?

+4
source share
2 answers

I assume that you have (starting from the left end) one signed bit, an assumed binary point, and then seven bits that represent a fractional value. If this is the case, then you can just take the signed integer value of the fixed-point number and divide by 128. You will need to do this separation using floating-point values, of course, because the result will be less than 1.

, , -1,0 + (127/128).

+2

, s = '1101001.1' (), :

d = int(s[0:7],2)+int(s[8])/2.0

unsigned, . , '1', , d, s[0] == '0' 64-d, s[0] == '1'.

+1

All Articles