if i could add one function to the python standard library, it would be sign extension for non-multiple-of-8-bit integers. i will not be taking questions at this time
-
-
Replying to @whitequark
I think there's a nice arithmetic form you can write arbitrary sign extension in, treating the input as unsigned.
1 reply 0 retweets 2 likes -
Replying to @RichFelker
can you write it for me? I tried to do so and felt like it would be more confusing to the reader than just a conditional
2 replies 0 retweets 1 like -
Replying to @whitequark
I think its +2^{n-1} in modular arithmetic then -2^{n-1} in integer arithmetic.
1 reply 0 retweets 2 likes -
Replying to @RichFelker @whitequark
Same concept as biased unsigned values vs signed values.
1 reply 0 retweets 0 likes
Replying to @RichFelker @whitequark
FWIW I really like this method for sign extend without branching. (Verilog because I can easily formally verify it. :)pic.twitter.com/HMMNHEqSzy
0 replies
1 retweet
9 likes
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.