Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Network to Host order


  • Please log in to reply
1 reply to this topic

#1 Baqs

Baqs

    New Member

  • Members
  • Pip
  • 5 posts

Posted 09 November 2012 - 03:17 AM

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?

#2 H07R0D

H07R0D

    Advanced Member

  • Members
  • PipPipPip
  • 95 posts

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:
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

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.