C# converting bytes (byte arrays) to other data types
There are basically two ways to do this:
1. Use the BitConvertor class.
To use this class, you need to keep track of where you want to read in the byte array
2. Use BinaryReader
This is the method I prefer, though it might be just a little bit slower than using the BitConvertor class (I am not sure of that though!)
Basically you can load your byte into a MemoryStream object. Then feed the memory stream to a BinaryReader object.
After that you just need to call the appropriate methods for conversion. Best of all the BinaryReader object keeps track of where in the stream you currently are reading from. Makes for some nice clean code. Just the way I like it!
No comments:
Post a Comment
Remember, if you want me to respond to your comment, then you need to use a Google/OpenID account to leave the comment.