LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to read this bin file!


SaintJokel wrote:

@Nathand, I don't understand how you previously detected the sign bit with the logical shift function and multiply by power of 2 function. It shifts the bits left or right depending on the y value. The idea is, if I'm correct that depending on the sign bit being positive (0) or negative (1) it should add or substract the other bits from the most sign bit value. For example having F93 --> 111110010011 sign bit is positive results in a negative number starting from -2048 downwards (011110010011 = 1939) so the real decimal value should be -109.


I haven't looked at your code yet to comment on it, just wanted to respond to this.  The multiply by power of 2 function does what it says.  If you multiply a negative number by a power of 2, you get a negative result, which is different than a simple bit shift.

 

Let's take the simple example of a 4-bit value of -1, which would be 1111 in binary.  Say you want to extend that to 8 bits.  You could shift 1111 4 bits left, resulting in 11110000 (0xF0, -16) and then multiply by 2**-4 (0.0625 or 1/16) resulting in a value of 11111111 (-1, 0xFF).  Same concept applies to extending 12 bits to 16.

0 Kudos
Message 21 of 22
(617 Views)

Hello SaintJokel,

 

How is it going with the reading of your file?

 

If you are still working on it, I can give you more explanation.

 

First, regarding the extension to 16bit signed integer, as nathand already explained you, it is really easy to do it with the "Scale by Power Of 2" function. Using that one, you don't have to care about the sign yourself. The function will proceed with the sign extension itself, and this is the very reason why that function is useful!! Do you understand that? Just have a look at the example nathand gave you on a previous post (Message 17). It really shows you nicely how to handle it !

 

To get the gain and offset data from your file, you can simply use the "Read From Text File" function and chose the "Read Lines" option (right-click on the function). Doing so, you can read a whole line of the file at a time. Then, use functions such as "Match First String" and/or "Match Pattern" from the String Palette to extract the different values you need. Finaly, use a "Decimal String to Number" function to transform the string to an integer. Moreover, you can use those same functions as well to look for your hexadecimal datas. Right ?

Cédric | NI Belgium
0 Kudos
Message 22 of 22
(574 Views)