2

Most IOTA libraries (at least C#, and Java) have a Converter, that has a getTrits method.

public static void GetTrits(
    sbyte[] bytes,
    int[] trits
)

It has two arrays as parameters. The input, bytes, and the output, trits. How can I compute the length of the necessary trits array for arbitrary length bytes?

1
  • I’m voting to close this question because it is about the legacy-network and it is a good idea to keep only Shimmer/ShimmerEVM and latest IOTA Chrysalis questions Commented Apr 24, 2023 at 14:03

1 Answer 1

3

The method you mentioned converts each byte into 5 trits, so the output array needs to be 5 times the length of the input array.

Note that this function is not suitable for encoding any byte combinations, as bytes with value 243 to 255 will result in an error. It is only suitable for converting bytes back into trits, which have been converted from trits to bytes before.

For other ways of converting between trits and bytes, see my answer to this question.

1
  • I saw the other answer, but it was too complex :D I think I'd rather convert the bytes to hex strings, since converting strings to trytes is easier! Thank you!
    – mike
    Commented Sep 20, 2018 at 20:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.