Inverting Binary Vales

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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#.
 
Thaynann said:
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#.

I think System.Net.IPAddress.NetworkToHostOrder will convert from little
endian to big endian and vice-versa.
 
Thaynann said:
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's mentioned a way of doing some big-endian stuff, and there's also
my EndianBitConverter 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);
 
Back
Top