Inverting Binary Vales

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Thaynann

    #1

    Inverting Binary Vales

    im new to working with binary data, i was wondering if tehr was an easy way
    to flip the values ie....f7 becomes 7f....things like that...im using c#.
  • Sean Hederman

    #2
    Re: Inverting Binary Vales

    "Thaynann" <Thaynann@discu ssions.microsof t.com> wrote in message
    news:D2A9ABFB-68ED-455B-903B-7AE019600435@mi crosoft.com...[color=blue]
    > im new to working with binary data, i was wondering if tehr was an easy
    > way
    > to flip the values ie....f7 becomes 7f....things like that...im using c#.[/color]

    I think System.Net.IPAd dress.NetworkTo HostOrder will convert from little
    endian to big endian and vice-versa.


    Comment

    • Jon Skeet [C# MVP]

      #3
      Re: Inverting Binary Vales

      Thaynann <Thaynann@discu ssions.microsof t.com> wrote:[color=blue]
      > im new to working with binary data, i was wondering if tehr was an easy way
      > to flip the values ie....f7 becomes 7f....things like that...im using c#.[/color]

      Sean's mentioned a way of doing some big-endian stuff, and there's also
      my EndianBitConver ter which allows you to specify which endianness you
      want: http://www.pobox.com/~skeet/csharp/miscutil

      However, that's not *quite* what you asked for - do you *really* want
      to flip nybbles? If so, it's as simple as:

      byte flipped = (byte)( (original & 0xf) << 4 |
      (original & 0xf0) >> 4);

      --
      Jon Skeet - <skeet@pobox.co m>
      Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

      If replying to the group, please do not mail me too

      Comment

      Working...