# Uint32 convert to real

## Recommended Posts

Trying to convert the HSC counter from a Uint32 to a real number so I can do math on the counter valve.

Tried to use Int to real no good, tried to multiply be 1 no good, tried Formula no good, tried all math no good.

Please let me know how to convert a Uint32 to real number.

- Andrew

##### Share on other sites

• MVP 2022

I did a little experimenting and learned the INT to Real block is looking for a INT16 data types as inputs.  Unfortunately this is not documented in the Help.

If you really want to do your math in REAL land you'll need to convert your UINT32 into two INT16s by dividing it by 10,000 and effectively creating a high word and a low word.  You can convert these to REALs and then combine them back together.

I realize this is a hack, but sometimes you have to work within the constraints of the product's functions.

You could also do your math directly on the UNIT32 using implied decimals.  What is the formula you're trying to implement?

Joe T.

• 1
• 1
##### Share on other sites

Thanks for your help.  A lot is not in the help. I'm using an encoder to calculate distance. This is not a fast moving.  1 P = .00124 inches.

I'm not sure I understand dividing by 10,000 . 4,294,967,295/2

Thanks

- Andrew

##### Share on other sites

Thanks for your help.  A lot is not in the help. I'm using an encoder to calculate distance. This is not a fast moving.  1 P = .00124 inches.

I'm not sure I understand dividing by 10,000 . 4,294,967,295/10,000

Daniel just answer me. He said use  Store Unsigned to signed this will work for what I'm doing.

Thanks

- Andrew

##### Share on other sites

• MVP 2022

I didn't realize an INT32 would work as the input to the INT to REAL block.  When you click on the little pencil to create a tag it defaults to an INT16, which is one way UniLogic is telling you what data types the block will accept.

Hope that works for you.  A limitation of the REAL data type is it can only handle 7 digits of precision, so as long as your counts don't go over 9,999,999 you'll be OK.

Joe T.

##### Share on other sites

• MVP 2022
15 hours ago, Joe Tauser said:

You could also do your math directly on the UNIT32 using implied decimals.

@AndrewTRSI, you're better off following this advice. If you're doing PLC programming, understanding this concept will improve your skills.

##### Share on other sites

• 8 months later...

I would like to say thanks also for your conversion tip.

I'm trying the DIV and MOD math blocks to create the HIGH WORD and the LOW WORD, both commands accept the UINT32 variable divided by 10000.

Then I'm using an OR block to add logically both INT16 registers into an INT32  register, in other words, the high and low word are INT16 and the final result after the OR operation is the

DOUBLE WORD (INT32) register that is suitable for the INT TO REAL command.

I compiled and rebuilt all without errors according to UNILOGIC.  It should work well based on your advice.

Very kind regards,

Marco👌

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×