Groups | Blog | Home
all groups > dotnet compact framework > july 2005 >

dotnet compact framework : UShort containing Bits to int, float etc...



Alex Feinman [MVP]
7/14/2005 10:53:15 AM
That depends on the format they are using, endiannes, width of bitfields for
float point numbers etc. Easiest would be if you could obtain a C reference
for data conversion from them. It'll be relatively simple to convert it to
C#.
In general a handy tool for conversions between simple data types is
Buffer.BlockCopy:

double[] a = new double[] { 1, 2, 3 };

byte[] b = new byte[Buffer.ByteLength(a)];

Buffer.BlockCopy(a, 0, b, 0, Buffer.ByteLength(a));

This converts an array of doubles into their memory representation as bytes.
Both target and source can be any of the basic types, like int, short,
double, even char.


--
Alex Feinman
---
Visit http://www.opennetcf.org
[quoted text, click to view]
Chris Tacke, eMVP
7/14/2005 1:55:33 PM
Take a look at the System.BitConverter class methods

--
Chris Tacke
Co-founder
OpenNETCF.org
Are you using the SDF? Let's do a case study.
Email us at d c s @ o p e n n e t c f . c o m
http://www.opennetcf.org/donate


[quoted text, click to view]

Marco [Stinger]
7/14/2005 4:47:28 PM
Hi
Newbe question:

I've got an external (Embedded C+) function that reads a PLC and returns an
array of 16 unsigned (PLC people call them WORD, but in C# thay should
be UShort).
That array contains the bits required to valorize a variable of variuos
kinds:
can be a char, Byte, Short, UShort, Int, UInt and Float.

THA QUESTION IS:
How do I convert in CF C# the BITS (or BitArray) contained in thoose
UShort in a Float (etc....)

PLEEEEEESE Help

Ciao
Marco

AddThis Social Bookmark Button