How to use the REAL TO BUF block
Hello. Someone can give me the explanation about REAL TO BUF.block. I really readed the document, but i don't understand about this. sorry if my english is not good.
Hello. Someone can give me the explanation about REAL TO BUF.block. I really readed the document, but i don't understand about this. sorry if my english is not good.
Comments
Hello.
One use-case for the REAL_TO_BUF block would be if you want to break up a single REAL value into its four individual bytes.
REAL values are stored in 4 bytes in single-precision floating-point format, according to IEEE 754.
The following code converts a single REAL value (123.456) into its four constituent bytes, on the rising edge of the
Request
boolean variable:Here is the Variables sheet, showing the data types of the FB parameters:
You can see that the first four elements of the BYTE array contain data, which (you can be assured!) represent the four bytes of the original number in IEEE 754 format. You can check this using any online converter, like this one:
... where you can see that the hexadecimal representation of the number 123.456 corresponds to the values of the four bytes generated by the REAL_TO_BUF function block.
If you don't like the byte order generated by the FB, you can swap this by setting the BUF_FORMAT parameter to TRUE.
Hope this helps.
~ Martin.
Hello, there are something wrong with the images. Could you fix it?
Thanks,
Sorry about that, during various "upgrades" of this Forum in the past, images - and even entire conversations - have been lost.
Here are the three images from the above conversation:
Thanks