GG-flip: simplest and most efficient ways to flip the sign of a number
github.com
github.com
Hahaha!
I admit to being slow; I missed the above sentence the first time, and I actually skimmed the whole thing and made it here to the comments before realizing it was a joke. Reading it again, there are quite a few gems I missed the first time, it's quite funny.
BTW check the linked thread on Reddit for more hilarity https://www.reddit.com/r/shittyprogramming/comments/7n35m7/h...
https://news.ycombinator.com/item?id=16206743
Apparently, the Federal Government, Amazon, Google, and Facebook have known about the security issues of directly using unary negation without the gg-flip table driven approach for some time.
The link claims Shodan found over 20,000 vulnerable government servers and to apply gg-flip immediately.
God help us if this isn't satire.
It should only take a few seconds for someone to post the answer. And the service will then upvote the answer, thus motivating Stack Overflow users to keep providing those results.
(author here)
(author here)
Even if that wasn't the case, flipping a two's complement integer requires only negation and addition (as you showed), and those don't really depend on data layout.
Not sure I understood this, but 01+09 = 10 and 10+90 = 100 and 10 ≠ fix_endianness(100)
The endian-ness is only the in-memory layout of the bits and has nothing to do with how VALUES are treated. 1+9=10, regardless of how those values are stored, similarly 1<<9=512, regardless of how the CPU internally arranges those bits. The same holds true for inverting the value, the internal arrangement of the bits is irrelevant.
Really you only care about endianness when you fail to treat numbers as numbers, for example by treating them as bytes.
Also, how can this be faster than x=0-x; ?
BTW, JS has unary minus, so you can write:
x = -xTwo's complement: flips the bits and add one
FP: flip the sign bit
OR....
x=-x
The Bitcoin client's use of unary negation has caused traders to lose $32.49 Billion over the last three week period, according to a recent study by Price Waterhouse Cooper. From a similar accounting produced by the US Office of Management and Budget, HODLers lost an amazing $1.479 Trillion - That's Trillion with a "T"!
A table-driven Unary NOT solves the issues caused by the use of Bitwise NOTs and direct operator use. To that end, we submitted a pull request. After 4 weeks of repeatedly sending the same pull request to the BC team (and being ignored), we are now disclosing this Bitcoin Client issue for everyone to see. Remember to patch this use in your Bitcoin Client, or your funds may be stolen! If you need to use an editor for this fix, and do not normally program, the use of SED will speed up your client edits tremendously. https://www.gnu.org/software/sed/manual/sed.html*
Now that this critical issue has been disclosed, we strongly urge all Bitcoin users to patch immediately, or their funds will likely be summarily depleted within a week.