LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to dynamically change data type

Hi 

 

Let say I have 1 byte in the folowwing hex format (1F )

 

Then if I say convert it to 24 bit then the number should become 1F 00 00 and if I say convert it 32 bit the number should become 1F000000

 

Could you please help me to implement this in LabVIEW ?

 

Thanks

0 Kudos
Message 1 of 7
(4,156 Views)

I don't quite understand the question. There's no 24-bit data type in LabVIEW; how would you convert it to 24-bit? Is the initial value always a single byte? If that byte is a string, you could just extend the string length, with 0's as the following characters.

0 Kudos
Message 2 of 7
(4,150 Views)

Hi,

 

Numeric -> Data manipulation -> Logical shift

 

I think this is what u want.

 

aaa.png

 

 

Patrick

Certified LabVIEW Developer
0 Kudos
Message 3 of 7
(4,147 Views)

I don't quite understand what you're asking as what you've posted is not quite right...if you convert 0x1F from 8-bit to 16-bit or 32-bit it is still 0x1F - prepended with 0's! The bit pattern would be 0x001F which is still 0x1F!

 

If you wanted 0x1F to become 0x1F00 (i.e. become a larger number) then you can left shift the number by the required number of bits or use the 'join numbers' with your U8 as the higher number.

 

Here are some examples that demonstrate:

2015-02-12_16-55-32.png

 

If you just want to display the prepending 0's, look at the display format property of the control/indicator.

 

 

 


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 4 of 7
(4,146 Views)

Thank you for the answers . Maybe this example expain it better

 

Let's say I have N number of 8 bit hex values ( in   this specific example 5 but it can be any number )

 

 

1F   2D   1E   11    15   then how can I programmatically make   1F2D1E1115

 

As I mentioned I don't know the N value so I assume I should use a loop

 

 

0 Kudos
Message 5 of 7
(4,100 Views)

You can use the scale by power two function to move 1F over 8 then add 2D, then move that sum over by 8 and add 11 and so on until you are out of numbers to add.

 

http://zone.ni.com/reference/en-XX/help/371361L-01/glang/scale_by_power_of_2/

Matt J | National Instruments | CLA
0 Kudos
Message 6 of 7
(4,093 Views)

Ah right, now I see why you mentioned dynamically changing the data type - LabVIEW is a strictly typed language which means you must end up with one of the numeric formats in LabVIEW (with 64-bits being the largest). If you're going to have more than 8 bytes, I'm not sure what the solution would be, if you're going to have 8 bytes or less then I would just assume the worst case and convert/fit the numbers into a U64.

 

Here's an example:

2015-02-13_09-47-55.png

 

I am starting off with an empty U64, taking each input byte and shifting the U64 left by one byte and then adding the input byte.

 

I guess that leads to my next question - what are you going to do with the numbers? Would having an array of U8's or converting the bytes to a character string not be better? If you have a string or array these can have a dynamic length so you can more easily manipulate the data (e.g. by performing string/array indexing functions).


LabVIEW Champion, CLA, CLED, CTD
(blog)
Message 7 of 7
(4,069 Views)