Internet PLC Forum
General => Technical support => Topic started by: kenobe on January 14, 2010, 10:19:46 PM
-
Hi
I can not find a function in Tbasic to convert hex number to dec number.
Can some one pls help.
Thanks
-
HEX and DEC only make sense to human. There is no underlying difference to the PLC between a DEC and HEX number since they are the same number. So you can't convert from dec to hex or dec to hex.
However, you can convert a "hex string" to a number using the "HEXVAL()" function. Likewise you can convert a number into hex string using the HEX$() function.
-
HI
Thanks for your advise.
The reason I need to convert a Hex number to Dec number is that
I need to send a telephone number (dec) to a modem to send SMS message( of course I ve to convert the dec number to string), the input device ( touch screen) responsible for capturing the user input feeds the T100MD888 with hex number and stored in DM[1] and DM[2]. I therefore need to extract the numbers from DM[1] and DM[2], convert them to dec numbers and later to strings and join them together.
I hope this explains my problem better.
Thanks
-
How does your touch screen store data into the DM[1] and DM[2]? I imagine it is via Modbus? If so, then the number that you enter as Hex in your touch screen is sent to the PLC DM[1] and DM[2] as an integer number. A number is always a binary number inside the CPU. Whether we look at it as decimal or hexadecimal is only for our own convenience since a number that is represented by 0 and 1 only is not easily readable by human.
You can understand what I mean by going online monitoring and then view the number as decimal or as hex by pressing the H or D key while in the "View variable" screen. The screen will show the number in either format. But that does not change the number itself.
When you need to format the number as a hexadecimal string, you can simply use the function HEX$(DM[1],4) to convert it into 4 digit hexadecimal number.
-
HI
Your suggestion works .
Thanks