LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Convert from PIC-Hex to IEEE754 decimal

Hi,

 

I have a 4 byte PIC-Hex value that I know the decimal equivalent of (8B 00 46 57 = 4104.79).

 

Initially the PIC-Hex is converted to normal Hex by shifting some bytes, which returns 45 80 46 57, which in turn is converted to 4104.79.

 

I'm struggling to find a method for converting from the initial state to the decimal state using LabVIEW, any help would be much appeciated.

 

Cheers

 

Chris

 

P.s. My knowledge of byte shifting is zero so any information on how to do it would be useful too.

0 Kudos
Message 1 of 9
(4,266 Views)

Chris Woodhams wrote:

Hi,

 

I have a 4 byte PIC-Hex value that I know the decimal equivalent of (8B 00 46 57 = 4104.79).

 

Initially the PIC-Hex is converted to normal Hex by shifting some bytes, which returns 45 80 46 57, which in turn is converted to 4104.79.

 



The value 4580 46 57, what is the datatype and how is this represented (if it's a string indidicator, is the display set to HEX?)?

8b004657 is not 4104,79 (see this online calculator)

Let's assume it is a string and the indicator is set to hex:

 

LabVIEW is fully based on IEEE754 and typecasting the data from string to sgl will do:

 

 

Ton

 

 

Message Edited by TonP on 01-19-2009 11:53 AM
Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
Message 2 of 9
(4,256 Views)

I know 8B 00 46 57 doesn't directly convert to 4104.79, first I have to convert the 8B 00 46 57 to 45 80 46 57 by shifting some of the bytes around.

 

Your solution works great for the conversion of 4580 4657 to decimal, I was inputting the string in a different format, I left a space between each byte (45 80 46 57)!

 

Do you know anything about shifting and carrying bytes?  Getting from 8B 00 46 57 to 45 80 46 57.

 

Chris

0 Kudos
Message 3 of 9
(4,243 Views)

I have been looking at the (bit-wise) data.

If you shift the bits of the first 2 bytes (word) to the right you get the transaction (I have shift bits). Why one would only shift the upper word I have no idea.

Here's the full conversion:

 

 

Ton

Message Edited by TonP on 01-19-2009 12:50 PM
Message Edited by TonP on 01-19-2009 12:51 PM
Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
Message 4 of 9
(4,238 Views)

That is brilliant, thank you!

 

I have one more question!  The format that the string is read is not in the format (with a space after two bytes) that LabVIEW requires at the input to the type cast, how do I get it into that format and ensure it is in Hex format as well?  That might not make sense so I have attached a vi of the string that is read and what I tried.

 

I don't know why it would be set up like that, this is how I have recieved it from the supplier.

 

Cheers

 

Chris

0 Kudos
Message 5 of 9
(4,229 Views)

Chris Woodhams wrote:

That is brilliant, thank you!

 

I have one more question!  The format that the string is read is not in the format (with a space after two bytes) that LabVIEW requires at the input to the type cast,


Chris


You are welcome, (kudos too).

The string as shown in the codesnipet I added is a normal string, set to HEX format (right click on the control, Hex-Display), if you have set the string to normal display and see the hex-string you have to convert the data with the string-numericconverserion.

 

EDIT:looked at your attachment and see you have a normal string (ASCII display) with hex-like strings:

 

 

Suggestion for study try to understand the differences between the last two code snippets!

 

Ton

 

Message Edited by TonP on 01-19-2009 01:59 PM
Message Edited by TonP on 01-19-2009 01:59 PM
Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
Message 6 of 9
(4,217 Views)

This is how to I think. Your string is a hex number in stringformat. So you have to convert it to a U32 before you convert it as TonP did.

 

As I was writing TonP was quicker to came up with a solution 😉
Message Edited by t06afre on 01-19-2009 02:10 PM


Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
(Sorry no Labview "brag list" so far)
0 Kudos
Message 7 of 9
(4,213 Views)

ThankThank you for all your help, much appreciated, everything is working as expected.

 

With regards to understanding the difference between the two code snippets, it is purely understanding the difference between type cast and numeric conversions?

 

Thanks again

 

Chris

0 Kudos
Message 8 of 9
(4,193 Views)

Chris Woodhams wrote:

With regards to understanding the difference between the two code snippets, it is purely understanding the difference between type cast and numeric conversions?

 


Yes it is, and the display mode of the string.

 

Ton

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 9 of 9
(4,188 Views)