deividasn

Extracting Digits of a Number

4 posts in this topic

Hello programmers, maybe sameone can  help me,

i have a number  for example 458 how to extract this number to  digits ?

4

5

in Twincat or codesys?

 

tx!

 

 

Share this post


Link to post
Share on other sites

You could convert to string and process each character to a number.

Or  you could divide by 10,  multiple the remainder by 10.

Then subtract the remainder from the divide result and repeat the above line until a single digit remains.

 

1 person likes this

Share this post


Link to post
Share on other sites

exactly... or convert it to BCD. many PLCs will have ready instruction for that. TwinCat has it too - lookup DEC_TO_BCD. in BCD each digit is in separate nibble (4 bit block)

1 person likes this

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now