02-12-2015 10:41 AM
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
02-12-2015 10:50 AM
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.
02-12-2015 10:53 AM
Hi,
Numeric -> Data manipulation -> Logical shift
I think this is what u want.
Patrick
02-12-2015 10:56 AM - edited 02-12-2015 10:56 AM
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:
If you just want to display the prepending 0's, look at the display format property of the control/indicator.
02-12-2015 10:26 PM
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
02-12-2015 11:37 PM
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/
02-13-2015 03:50 AM - edited 02-13-2015 03:50 AM
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:
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).