|
Here you go[^]
Cheers,
Vikram. Current activities:
Films: The classic Pink Panther series
TV series: Friends, season 3
Books: Liar's Poker, by Michael Lewis. Carpe Diem.
|
|
|
|
|
you really need to see this website. www.lmgtfy.com . It's much more informative
|
|
|
|
|
String hexNumber = "4363A00E";
int i = Int32.Parse(hexNumber, System.Globalization.NumberStyles.HexNumber);
Why do you want to display it in decimal? You can't create decimal with an hexa...
|
|
|
|
|
Hi,
Thanks for replying so soon. I am doing an application involving serial Port.I am getting data from Serial Port in Hexa decimal format(for eg.436300E).I need to convert that into floating point(eg.123.34).
Thanks
|
|
|
|
|
Data from a serial port generaly comes in as a stream of bytes, and are not amenable to conversion to float directly - parse probably wont work.
I assume your data is coming from a data logger or sillyscope or similar? You will have to give more detail on the incomming data stream before anyone can help you much.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Hexidecimal notation usually is always involved with integer values. To convert to a float, you'd need to convert to an integer first and then move into the floating point world.
Your hexidecimal representation, is it fixed point or floating point?
Regards,
Rob Philpott.
|
|
|
|
|
In that case what you need to do is use the BitConverter which will convert a set of bytes into another data type. To get your bytes (hopefully 4 of them) to a float you need to use ToSingle
So you'd have:
byte[] data = ...
float myFloat = BitConverter.ToSingle(data)
ToSingle also takes a second parameter (all of the functions in BitConverter do). The second parameter is the offset in the set of bytes where your float starts. That way if you had a stream you could just read all of the bytes out and then work your way through; rather than copying out 2 or 4 bytes to some other array all the time.
EDIT: You say your getting the data in hex format, I assume your just getting bytes which are usually represented as hex. If you are actually getting a string from the port then you'll need to convert that back into a set of bytes,.
My current favourite word is: Delicious!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
You may use a 'union' see [^]
[System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Explicit)]
struct TestUnion
{
[System.Runtime.InteropServices.FieldOffset(0)]
public UInt32 i;
[System.Runtime.InteropServices.FieldOffset(0)]
public Single s;
}
and then, for instance:
TestUnion tu = new TestUnion();
tu.i = UInt32.Parse("4363A00E", System.Globalization.NumberStyles.HexNumber);
Single s = tu.s;
However it gives 227.625214 as result (are you sure about the expected output?).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
any one knows that F#?
I want to know that there is already IDE for F#? or when it will be integrated with Visual studio? or already?
thanks
|
|
|
|
|
Try Googleing 'F#' and theres all the information you need.
My failometer is detecting vast quantities of FAIL!
"Its SQL - hardly programming..." (Caslen)
|
|
|
|
|
|
This is VERY close to a repost!
Why didn't you edit the original post or add a reply to yourself asking the exra information?
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
This is because people tend not to answer TOO MANY QUESTIONS IN ONE POST
dev
|
|
|
|
|
If you'd WAIT for an answer, it wouldn't be so noticable that you are double posting.
I've seen three questions from you inside one page. This is indicative of not actually trying anything and resorting to others before looking yourself first.
Make that SIX questions in ONE day!
Care to explain that?
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
it's NOT double post, get a grip mate. if you're trying to help, help. If not, go away.
dev
|
|
|
|
|
devvvy wrote: mate
I don't think so.
Can you try and WAIT or is that too difficult a concept?
There is a chance, however slim, that you may understand an answer. Extrapolation of that theory gives the concept of having been helped, the next problem becomes surmountable. So you should be getting /a grip/ and behaving.
Simple concept is to ask a question and wait for it to be answered.
Adding another question after two minutes shows, as previously stated, that you cannot be bothered to TRY first.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
mate, you're execellent, i suggest you stop littering the forum, lock yourself in a room with no internet connection and you can nag all you like day and night
dev
|
|
|
|
|
devvvy wrote: nag all you like
That's what I am payed to do.
Now, do you UNDERSTAND anything I've said? No you don't
0. The OP was regarding caspol and if you'd waited for an answer the chances are good that the help would have prevented the sencond posting.
1. You were not worried about multiple questions here[^].
2. I really can't be bothered - FOAD
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
you are worried? no you're just a kiss arse littering our board in name of great good.
dev
|
|
|
|
|
One thread does not a litter make.
devvvy wrote: our board in name of great good
That is just too garbled to make any sense. And YOU have the audacity to try and mock.
A word begining with T springs to mind; see if you can guess it without asking.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
how do you get the current user logged on to Moss to show in a text box using C#? custom webparts
|
|
|
|
|
hey,guys.I want to convert wap to web using c#?how to do that?
|
|
|
|
|
Interesting, I was going to be a smartass and do the usual LMGTFY but the results are all Web to WAP.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
... so you get a Web to WAP application and run it in "anti-process mode".
There are three kinds of people in the world - those who can count and those who can't...
|
|
|
|
|
molesworth wrote: run it in "anti-process mode"
No, no, no. Just turn your computer over so it runs backwards - doh!
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|