This forum is a read-only archive. Posting, replying and signing in are disabled.

How to I split Int in Teal

pagito

I want to convert int to byte using setbyte. So planning to do with subroutine, but I need to split the integer with individual digits. For example:

  • int 21
  • split: 2 and 1
  • convert 2 to “2”
  • convert 1 to “1”
  • concat “2” and “1”

How I can split int 21?

Thanks!

pagito

Thanks for the answer!

The end goal is to loop with a given X uint64 and for each loop var concatenate it with bytes, in order to construct known key. For instance key_1, …, key_24, … So i need that “24” in bytes to concat with “key_”. And I’m doing in TEAL.

pagito

Basically I need to split those uint64 with two digits. The rest can be done with setbyte by converting it to ascii.

Ben
↩ in reply to pagito

I see, if there is not a very strong reason to make it human readable i’d favor just using the bytes of the int.

In other words, for the integer idx, Suffix(idx, Int(6)) for up to max uint16 unique keys. This would be much more efficient than using ascii and would still provide the unique keys. Any client would have to know that you’re just appending the uint16 bytes but seems fine unless you have a very strong reason not to

edited
pagito

Ok. Would love to make it with human readable, but there is not much need of it. Sounds right using bytes of the int. Thanks Ben!