473,387 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

help float converting

I ve get float data from serial port. I ve taken it in the form of hex by
modbus protocol. I know it is float but I couldnt convert it
there is a few sample data below;

B3 33 43 34 = 180.699997
33 33 43 33 = 179.199997
B3 33 43 34= 180.699997
CC CD 43 33=179.800003

But how can I found it. I couldnt resolve it.

Apr 22 '07 #1
4 4777
Yasin,

Unfortunately, there is nothing in the framework that will help you with
this. I would say use the BitConverter class, but it will not convert the
byte array using the modbus protocol. It uses the IEEE format for floating
point numbers.

You will have to write this yourself.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Yasin Cepeci" <ce****@gmail.comwrote in message
news:OS**************@TK2MSFTNGP03.phx.gbl...
>I ve get float data from serial port. I ve taken it in the form of hex by
modbus protocol. I know it is float but I couldnt convert it
there is a few sample data below;

B3 33 43 34 = 180.699997
33 33 43 33 = 179.199997
B3 33 43 34= 180.699997
CC CD 43 33=179.800003

But how can I found it. I couldnt resolve it.

Apr 22 '07 #2
On Sun, 22 Apr 2007 22:13:03 +0300, "Yasin Cepeci" <ce****@gmail.com>
wrote:
>I ve get float data from serial port. I ve taken it in the form of hex by
modbus protocol. I know it is float but I couldnt convert it
there is a few sample data below;

B3 33 43 34 = 180.699997
33 33 43 33 = 179.199997
B3 33 43 34= 180.699997
CC CD 43 33=179.800003

But how can I found it. I couldnt resolve it.

It looks as if you just need to reorder the bytes and cast to float.

180.70000 -33-B3-34-43
179.20000 -33-33-33-43
180.70000 -33-B3-34-43
179.80000 -CD-CC-33-43

Code used:

static void Main() {

float[] test = { 180.699997F,
179.199997F,
180.699997F,
179.800003F };
foreach (float ff in test) {
byte[] bytes = BitConverter.GetBytes(ff);
Console.WriteLine("{0:F5} -{1}",
ff, BitConverter.ToString(bytes));
}
} // end Main()

rossum

Apr 22 '07 #3
O I See but How can I turn the converting proccess below reverse. in other
words convert to float from hex or binary(32bit).
10101010101011111101101010101010--->xxx.xxxxxF; to float value:)

"rossum" <ro******@coldmail.com>, haber iletisinde sunlari
yazdi:3c********************************@4ax.com.. .
On Sun, 22 Apr 2007 22:13:03 +0300, "Yasin Cepeci" <ce****@gmail.com>
wrote:
>>I ve get float data from serial port. I ve taken it in the form of hex by
modbus protocol. I know it is float but I couldnt convert it
there is a few sample data below;

B3 33 43 34 = 180.699997
33 33 43 33 = 179.199997
B3 33 43 34= 180.699997
CC CD 43 33=179.800003

But how can I found it. I couldnt resolve it.

It looks as if you just need to reorder the bytes and cast to float.

180.70000 -33-B3-34-43
179.20000 -33-33-33-43
180.70000 -33-B3-34-43
179.80000 -CD-CC-33-43

Code used:

static void Main() {

float[] test = { 180.699997F,
179.199997F,
180.699997F,
179.800003F };
foreach (float ff in test) {
byte[] bytes = BitConverter.GetBytes(ff);
Console.WriteLine("{0:F5} -{1}",
ff, BitConverter.ToString(bytes));
}
} // end Main()

rossum

Apr 23 '07 #4
Yasin Cepeci wrote:
O I See but How can I turn the converting proccess below reverse. in other
words convert to float from hex or binary(32bit).
10101010101011111101101010101010--->xxx.xxxxxF; to float value:)
Us the BitConverter.ToString method to convert four bytes of a byte
array into a float value.
>
"rossum" <ro******@coldmail.com>, haber iletisinde sunlari
yazdi:3c********************************@4ax.com.. .
>On Sun, 22 Apr 2007 22:13:03 +0300, "Yasin Cepeci" <ce****@gmail.com>
wrote:
>>I ve get float data from serial port. I ve taken it in the form of hex by
modbus protocol. I know it is float but I couldnt convert it
there is a few sample data below;

B3 33 43 34 = 180.699997
33 33 43 33 = 179.199997
B3 33 43 34= 180.699997
CC CD 43 33=179.800003

But how can I found it. I couldnt resolve it.

It looks as if you just need to reorder the bytes and cast to float.

180.70000 -33-B3-34-43
179.20000 -33-33-33-43
180.70000 -33-B3-34-43
179.80000 -CD-CC-33-43

Code used:

static void Main() {

float[] test = { 180.699997F,
179.199997F,
180.699997F,
179.800003F };
foreach (float ff in test) {
byte[] bytes = BitConverter.GetBytes(ff);
Console.WriteLine("{0:F5} -{1}",
ff, BitConverter.ToString(bytes));
}
} // end Main()

rossum


--
Göran Andersson
_____
http://www.guffa.com
Apr 23 '07 #5

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

Similar topics

1
by: Giovanni Azua | last post by:
Hello all, I need to return back to TSQL two numeric values from an Extended Stored Procedure developed in C. As result my C dll program produces two float values, the TSQL side expects to have...
2
by: Patrick.O.Ige | last post by:
Can anyone help in converting the code below to VB.NEt! Thx protected void myDataGrid_OnItemDataBound(object sender, DataGridItemEventArgs e) { if(e.Item.FindControl("DeleteLink") != null) {...
4
by: Patrick.O.Ige | last post by:
Hi All, Can anybody help in converting the code below to VB.NEt thanks. I need the loop converted.. thanks Private Sub expandCollapseAllTreeviewNodes(ByVal nodes As TreeNodeCollection, ByVal...
6
by: Patrick.O.Ige | last post by:
Can someone help me convert the code below to VB.NET. Thanks Function getXML(ByVal sourceFile As String) Dim myRequest As System.Net.WebRequest = System.Net.WebRequest.Create(sourceFile) ...
7
by: MeganTSU | last post by:
Hey yall! I am trying to get this program finished for class.... It says that you are suppposed to write a program that will display a check formatted out put (the output looks like a check). I got...
0
by: jonipony | last post by:
HELP: Float Left box is drifting to the right in ie! -------------------------- I need som HELP with my CSS coding! On the following web page my design falls apart at screen size 800 x 600...
32
by: robert d via AccessMonster.com | last post by:
I'm looking at converting DAO to ADO in my app. All of my DAO connections are of the following structure: Dim wsName As DAO.Workspace Dim dbName As DAO.Database Dim rsName As DAO.Recordset ...
2
Mhel
by: Mhel | last post by:
Hi everyone! I need some help in Converting Infix to postfix.I need a program that would do it. Please, I really need help.
1
by: danmilkman | last post by:
Hi Y'all Can someone help me convert the next few lines of code from c++ to c#? I've given it a try myself but my program keeps crashing when I use my c# code. I think the difficulty lies in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

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.