471,356 Members | 1,543 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,356 software developers and data experts.

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#.
Jul 21 '05 #1
2 1051
"Thaynann" <Th******@discussions.microsoft.com> wrote in message
news:D2**********************************@microsof t.com...
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.
Jul 21 '05 #2
Thaynann <Th******@discussions.microsoft.com> wrote:
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);

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

20 posts views Thread by Christian Stigen Larsen | last post: by
3 posts views Thread by Tron Thomas | last post: by
9 posts views Thread by Ching-Lung | last post: by
1 post views Thread by spalding | last post: by
2 posts views Thread by Thaynann | last post: by
10 posts views Thread by rory | last post: by
16 posts views Thread by Erwin Moller | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.