Component: Type Conversions Free (Calculation)
Author | Matrix TSL |
Version | 1.0 |
Category | Calculation |
Contents
Type Conversions Free component
Component to simplify the task of converting data into different bit type variables. Allows conversion between Bytes, Ints, Longs and Floats. Useful when you need to store Ints, Longs and Floats into Byte based memory. Uses a simple 32-bit C Union to overlay the following variable types into the same RAM space. Byte[4], Int[2], Long, Float
Component Source Code
Please click here to download the component source project: FC_Comp_Source_TypeConversionsFree.fcfx
Please click here to view the component source code (Beta): FC_Comp_Source_TypeConversionsFree.fcfx
Detailed description
No detailed description exists yet for this component
Examples
The type conversion component is aimed at allowing for simple, relible and efficient ways of converting between 8-bit, 16-bit and 32-bit values.
The component consists of a single 32-bit block of memory that consists of the following data types which are all overlaid on each other.
4 x 8-bit Bytes
2 x 16-bit INTs
1 x 32-bit Long
1 x 32-bit Float
- MSB = Most significant bit
- LSB = Least significant bit
For communications systems you may need to send or receive data as bytes.
So to pack up a float into bytes you would load a floating point value and then collect the 4 bytes.
To repack the floating point value at the other end you would load the 4 bytes and then collect the floating point value.
Here is a simple project showing how to convert between bytes, ints, longs and floats.
Macro reference
GetByte
![]() |
GetByte |
Gets a single 8-bit BYTE value. Index is in little endian, 0 is the LSB and 3 is the MSB | |
![]() |
Index |
Range: 0-3 | |
![]() |
Return |
GetFloat
![]() |
GetFloat |
Gets a single 32-bit FLOAT value | |
![]() |
Return |
GetInt
![]() |
GetInt |
Gets a single 16-bit INT value Index is in little endian, 0 is the LSW and 1 is the MSW | |
![]() |
Index |
Range: 0-1 | |
![]() |
Return |
GetLong
![]() |
GetLong |
Gets a single 32-bit LONG value | |
![]() |
Return |
SetByte
![]() |
SetByte |
Sets a single 8-bit BYTE value Index is in little endian, 0 is the LSB and 3 is the MSB | |
![]() |
Index |
Range: 0-3 | |
![]() |
Value |
Range: 0-255 | |
![]() |
Return |
SetFloat
![]() |
SetFloat |
Sets a single 32-bit FLOAT value | |
![]() |
Value |
Range: 0-4294967295 | |
![]() |
Return |
SetInt
![]() |
SetInt |
Sets a single 16-bit INT value. Index is in little endian, 0 is the LSW and 1 is the MSW | |
![]() |
Index |
Range: 0-1 | |
![]() |
Value |
Range: 0-65535 | |
![]() |
Return |
SetLong
![]() |
SetLong |
Sets a single 32-bit LONG value | |
![]() |
Value |
Range: 0-4294967295 | |
![]() |
Return |
Property reference
![]() |
Properties |
![]() |
Generate Code |