in reply to Flipping the Sign Bit in pack()'ed Value

Are you sure a "sign bit" is what you have here? IEEE formats have a sign bit, but plain integers are generally 2's complement, so you need to potentially modify every bit to switch between positive and negative. But maybe your example is just omitting those details.
  • Comment on Re: Flipping the Sign Bit in pack()'ed Value

Replies are listed 'Best First'.
Re^2: Flipping the Sign Bit in pack()'ed Value
by ikegami (Patriarch) on Jun 09, 2025 at 15:55 UTC

    With two's complement, flipping the "sign" bit will have the effect of subtracting the max negative value (if 1) or adding the max negative value (if 0).

      ikegami wrote:

      With two's complement, flipping the "sign" bit will have the effect of subtracting the max negative value (if 1) or adding the max negative value (if 0).

      Yep. I'm looking for a specific effect and when I expanded the test data to 32-bit integers I saw my error right away.

      It's painfully obvious I haven't done bit-head work in awhile, and it's also painfully obvious that I've been working in PowerShell too much and not enough Perl for far too long.

      I hate to say it, but it's also becoming painfully obvious that my mental faculties are slowing down. Getting old sucks. :-)

      I appreciate the help, though. Thank you.

Re^2: Flipping the Sign Bit in pack()'ed Value
by marinersk (Priest) on Jun 10, 2025 at 02:31 UTC

    NERDVANA wrote:

    Are you sure a "sign bit" is what you have here?

    Yeah, once I got the behavior I was looking for out of the instructions, I then realized I hadn't thought through the problem very well. Already adjusting the algorithm. Just ... y'know, needed the steps to behave (or, more to the point, get my understanding of how the steps would behave in alignment with reality, but, y'know, that's a lotta' words. :-) )

    It's interesting. I'm creating a new standard which is neither Big-Endian nor Little-Endian.

    I think it might need to be dubbed "Bad Endian" when I get it working. :-(
    But it will do what I need and that's of course the final arbiter.

    Thanks for the help and advice. I appreciate it.