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?

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.

  • 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 Sep 20 '18 at 20:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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