Hi
After searching for a while I have been unable to find the equivalent of the BitConverter class in NETMF. I am totally new to NETMF programming so until now I assumed there was an equivalent class somewhere because I find it hard to believe that an embedded networked device does not have support for byte ordering to transmit/receive binary data. But after reading a few articles and browsing the .NET Micro Framework Platform SDK I am becoming convinced that there is no such class.
Before I write my own class using pointers, which seems as elegant as putting a set of bicycle tires on an F1 car, I want to make sure that I am not missing something. So my question is
Is there an equivalent of the BitConverter class in .NET Micro Framework, i.e. is there a class which will let me access the bytes of an int, float, etc, as an array of bytes?
Network to Host order
Started by Baqs, Nov 09 2012 03:17 AM
1 reply to this topic
#1
Posted 09 November 2012 - 03:17 AM
#2
Posted 09 November 2012 - 01:21 PM
I've never seen it around, but that's just because Bit Shifting in general is pretty straight forward.
I don't see any advantage to wrapping extremely simple commands, especially when encapsulation can be costly at times.
If you want to access individual bits, you could do something like this:
This would allow you to extend the Int class to do some simple bit set operations.
You could continue on with whatever else you would need.
I just do the bit shifting in the routines where it's needed as opposed to extending a class.
I don't see any advantage to wrapping extremely simple commands, especially when encapsulation can be costly at times.
If you want to access individual bits, you could do something like this:
public static class IntExtensions { public static int SetBit(this int _val, int _pos) { _val |= (0x01 << _pos); return _val; } }
This would allow you to extend the Int class to do some simple bit set operations.
You could continue on with whatever else you would need.
I just do the bit shifting in the routines where it's needed as opposed to extending a class.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users