LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

byte calculation of a number

Dear

In writing a code for manipulating byte of a number, I got to know here a simple method using typecasting function.

Could you recommand a method for calculating "checksum" not using split byte functions?

Thank you in advance

메시지가 10-18-2005 08:37 PM에 labmaster에 의해 편집되었음

메시지가 10-18-2005 08:37 PM에 labmaster에 의해 편집되었음

0 Kudos
Message 1 of 6
(11,131 Views)
Just cast it to an U8 array.
0 Kudos
Message 2 of 6
(11,116 Views)
Thank you.
 
I hadn't an experience in using the typecasting function.
In C language, typecasting is used to change the data type.
Is it right?
 
But in labview, U32 can be changed  to a U8 array of 4 elements.
 
Could you tell me the usage of the typecasting function in detail? 
 
Thanks again. 
0 Kudos
Message 3 of 6
(11,111 Views)
You can righ-click on any item in LabVIEW and select help. the online help is pretty good, try it. 🙂
 
In this partcular case the bit pattern originally representing the U32 array is re-interpreted as an 4 times longer array of U8 elements.
 
Somewhat simplistically, you can think of it this way:
 
Typecasting: bit patterns remain the same, the values might change.
Conversion (e.g. DBLtoI32): values remain the same, bit patterns will change.
 
0 Kudos
Message 4 of 6
(11,105 Views)
Altenbach, the help is usually good, but in this case (at least in 7.0) it's very obscure. According to the help, Type Cast Casts x to the data type by flattening it and unflattening it using the new data type. It doesn't make any mention of the bit pattern. Furthermore, try flattening a U32 array to a string and unflattening it as a U8 array. You will see the result is different from typecasting it to a U8 array, so the help is even confusing in this case. There doesn't seem to be any mention of it in the bookshelf either, unless you dig a bit into the data storage one, which explains flattened data a bit (it doesn't refer to Type Cast, though). The help for Flatten to String says that you should use Type Cast for simple conversion of data types that does not result in flattened data which doesn't explain it any better.

___________________
Try to take over the world!
0 Kudos
Message 5 of 6
(11,097 Views)
Yes, that's where "somewhat simplistic" comes into play ;), because I don't mention endian-ness, etc. where the details under the hood are quite a bit more complex than they appear on the surface. Still, if you use my rule of thumb for simple cases, they are conceptually valid. 🙂
 


@tst wrote:
Furthermore, try flattening a U32 array to a string and unflattening it as a U8 array. You will see the result is different from typecasting it to a U8 array, so the help is even confusing in this case.

But.... typecasting a U32 array to a string then typecasting to a U8 array produces the same result as typcasting the U32 array directly to an U8 array. 🙂
 
(The flatten/unflatten operations have received a huge makeover in the upcoming LabVIEW 8.0, where you now can select byte order and decide if the string/array sizes are included in the flattened data. They can be made to act exacly as the typecast and also work in the above mentioned case. Still you need to mind your bits and bytes...).
 
I agree, the help for typecast is a bit sparse.
 
0 Kudos
Message 6 of 6
(11,084 Views)