473,473 Members | 2,074 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to convert a bit pattern stored in 2 ushorts to a float

I am reading values from a device through a TCP/IP socket that represent an
ANSI float value. However, the values come across as 2 elements in a ushort
array. I need to map the 2 values bit patterns into a floating point number
to get the actual float values being returned.

In C++ I'd finagle it using pointers since a pointer is analogous to an
array. I could just create a ushort pointer, give it the address of a float
variable and assign the values to the pointer using array notation. The float
variable would then have the proper bit pattern.

I don't know how to do that type of thing in C#. Anyone out there know how?

Thanks,

Mike
Aug 23 '07 #1
1 3344
Hi,

"flyfisher1952" <fl***********@discussions.microsoft.comwrote in message
news:95**********************************@microsof t.com...
>I am reading values from a device through a TCP/IP socket that represent an
ANSI float value. However, the values come across as 2 elements in a
ushort
array. I need to map the 2 values bit patterns into a floating point
number
to get the actual float values being returned.

In C++ I'd finagle it using pointers since a pointer is analogous to an
array. I could just create a ushort pointer, give it the address of a
float
variable and assign the values to the pointer using array notation. The
float
variable would then have the proper bit pattern.

I don't know how to do that type of thing in C#. Anyone out there know
how?
Take a look at BitConverter class
Aug 23 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Maciej | last post by:
Hello I have some problems with converting varbinary to float in T-SQL stored procedure. In my C# application i have table of structures with double type fields. Size of this table is variant. I...
4
by: aevans1108 | last post by:
expanding this message to microsoft.public.dotnet.xml Greetings Please direct me to the right group if this is an inappropriate place to post this question. Thanks. I want to format a...
2
by: Goran | last post by:
Hi! I need to convert from a unsigned char array to a float. I don't think i get the right results in the program below. unsigned char array1 = { 0xde, 0xc2, 0x44, 0x23}; //I'm not sure in...
2
by: philippe sillon | last post by:
Hi, I have a problem to implemente the strategy pattern. the problem come from that a method take different arguments type (object in interface and String / Int in implemented class). When...
7
by: farseer | last post by:
Here is the scenario: I have an interface which defines get methods for data that will make up a row in a table. However, the source of this data may, over time, switch/change (The company may...
4
by: Gav | last post by:
Hi all, I have a value in a database which is of float and in order to get my value from my textbox into my database I am doing something along the line of sqlparm1.value=...
2
by: bilbo2000 | last post by:
I am trying to read in a binary file which has the data stored as 32 bit float. I have been trying to figure out how to read this in as 32 bit but everytime I try to read it in the best I can do...
28
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places?...
12
by: Peter | last post by:
Trying to convert string to byte array. the following code returns byte array of {107, 62, 194, 139, 64} how can I convert this string to a byte array of {107, 62, 139, 65} ...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.