News for hackers. Stuff that matters.
Re:GG-flip: simplest and most efficient ways to flip the sig... by Ono-Sendai on Saturday January 20, 2018 @09:43PM (#16196610)
The usual/obvious solution is to flip the sign bit. (for floating point numbers). I think you're right for two's complement integers.
Re:GG-flip: simplest and most efficient ways to flip the sig... by perl4ever on Saturday January 20, 2018 @10:21PM (#16196716)
I was kidding...but I was also thinking of the thread where people were discussing big vs little endian and the idea that since nobody uses big endian any more, it's not necessary to allow for it.
Re:GG-flip: simplest and most efficient ways to flip the sig... by OskarS on Sunday January 21, 2018 @06:05AM (#16197612)
Endianess only matters for how numbers are stored in memory, but operations like bitshifts, boolean operations and arithmetic happen after the number has been loaded into a processor register, so endianess doesn't matter.

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.

Re:GG-flip: simplest and most efficient ways to flip the sig... by gugagore on Sunday January 21, 2018 @08:00AM (#16197892)
> 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)

Re:GG-flip: simplest and most efficient ways to flip the sig... by rkeene2 on Sunday January 21, 2018 @01:33PM (#16199270)
10!=01 and 09!=90

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.