Jump to content

Recommended Posts

Posted

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!

 

 


Posted

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.

 

  • Like 1
Posted

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)

  • Like 1

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
×
×
  • Create New...