LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

decimal to array

Solved!
Go to solution

Hello,

 

I have a to convert a float number to U8 array format how to do this ?

 

example 0.6 should be XX XX XX XX.

1.2 should be YY YY YY YY

 

array size should be 4 only.

 

I did try using string to byte array function but I do not know whether it is proper or not?

because for 1.2 I got the answer as 49 46 50 (byte 0,1,2)

 

Thanks

0 Kudos
Message 1 of 7
(3,064 Views)

Is this what you are looking for?

 

 

SingleFloatToU8array.png

Omar
0 Kudos
Message 2 of 7
(3,066 Views)

Well if you type 0.35 as input number the type cast gives me array size of 16.

 

I need to convert 0.35 (or any number) to array format but array size should only be 4 & when I reconvert array I should get back the same input number.

0 Kudos
Message 3 of 7
(3,053 Views)

The size of a single float is only 4 bytes.

 

Your starting data type must be bigger than a Single. A double is only 8 bytes.

 

What data type are you using as your input?

 

The example will only give you 4 bytes no matter what number you type in.

Omar
0 Kudos
Message 4 of 7
(3,053 Views)
Solution
Accepted by topic author systemcrash

 


@systemcrash wrote:

Well if you type 0.35 as input number the type cast gives me array size of 16.

 

I need to convert 0.35 (or any number) to array format but array size should only be 4 & when I reconvert array I should get back the same input number.


What is the data type of your FLOAT? Single is 4 bytes, Double is 8

I do not know where you are getting an array size of 16

 

Is this what your are trying to get the 32 bits of a Single Float?

Single

Single-precision floating-point numbers have a 32-bit IEEE single-precision format.

 

SingleFloatToU8arrayAndBack.png

 

Put .35 in and you get .35 back

Omar
Message 5 of 7
(3,048 Views)

I think I overlooked some stuff,

 

Thank you Omar II

0 Kudos
Message 6 of 7
(3,033 Views)

 


@Omar II wrote:

 

I do not know where you are getting an array size of 16

That would be an EXT data type

 

 

0 Kudos
Message 7 of 7
(3,027 Views)