Reputation: 27
It's BitConverter.ToString(blabla) same with blabla.toString?
Example:
int values = 1500;
byte[] bytes = BitConverter.GetBytes(values);
byte[] bits = new byte[2];
bits.SetValue(bytes[0], 0);
bits.SetValue(bytes[1], 1);
string hex = BitConverter.ToString(bits);
string hexHub1 = hex.Substring(0, hex.IndexOf("-"));
string hexHub2 = hex.Substring(hex.IndexOf("-") +1,2);
And get "DC-05"
How can i implement anything like this in kotlin?
Upvotes: 0
Views: 503
Reputation: 50558
byteArray.toString()
is used to convert ByteArray
to String
. On the other hand, contentToString()
will result elements in the array.
val byteArray = "Hello".toByteArray(Charsets.UTF_8)
println(byteArray.contentToString()) // this will print numbers
println(byteArray.toString(Charsets.UTF_8))
Upvotes: 1