Reversal of .bin()
See original GitHub issueI’m wondering if there is a way to revert calling .bin()
. Something like:
x1 = Fxp(3.4)
x_bin = x1.bin()
x2 = from_bin(x_bin)
assert x1 == x2
My use case is to convert into the notation, do some operations, then convert the result back over. I see the constructor can take in a binary value but it looks like it only takes in a “normal” python bit string. Is this possible currently?
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Reverse actual bits of the given number - GeeksforGeeks
Given a non-negative integer n. The problem is to reverse the bits of n and print the number obtained after reversing the bits....
Read more >Slick way to reverse the (binary) digits of a number in Python?
int(reversed(s),2) == f(int(s,2)) whenever s is a string of zeros and ones starting with 1. Right now I am using lambda x: int(''.join(reversed(bin(x)[2:])),2)....
Read more >Simple Tools and Techniques for Reversing a binary - bin 0x06
Exploring and comparing some common tools and techniques for reversing binaries.https://github.com/radare/radare2-=[ Stuff I use ] ...
Read more >Python: Reverse the binary representation of an integer and ...
def test(n): return int(bin(n)[::-1][:-2], 2) n = 13 print("Original number: ", n); print("Reverse the binary representation of the said ...
Read more >Python program to reverse bits of a positive integer number?
First convert number into binary using bin() function. Then skip the first two character of binary representation because bin() appends 0b ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes, it would be good! I’ll try to include that in next release. Thanks for the recommendation.
As you are using 2 bits for fractional part, 256.2 is rounded to 256.0. You need more fractional bits to get a fixed-point value closer to 256.2.
With 2 bits for fractional part, the closer values to 256.2 are 256.0 and 256.25. If you use
rounding='ceil'
orrounding='around'
, you will get a fixed-point value of 256.25 instead of 256.0.If you fix the
n_word
size to 32 but let toFxp
finds the best fractional part: