How many bits is a “word”?

I’m not familiar with either of these books, but the second is closer to current reality. The first may be discussing a specific processor. Processors have been made with quite a variety of word sizes, not always a multiple of 8. The 8086 and 8087 processors used 16 bit words, and it’s likely this is …

Read more

Converting a byte array into a hex string

As I am on Kotlin 1.3 you may also be interested in the UByte soon (note that it’s an experimental feature. See also Kotlin 1.3M1 and 1.3M2 announcement) E.g.: @ExperimentalUnsignedTypes // just to make it clear that the experimental unsigned types are used fun ByteArray.toHexString() = asUByteArray().joinToString(“”) { it.toString(16).padStart(2, ‘0’) } The formatting option is …

Read more

How many bytes will a string take up?

From my article on strings: In the current implementation at least, strings take up 20+(n/2)*4 bytes (rounding the value of n/2 down), where n is the number of characters in the string. The string type is unusual in that the size of the object itself varies. The only other classes which do this (as far …

Read more

convert Byte Array to Secret Key

You need to use the new keyword to call the constructor and create the object. SecretKey originalKey = new SecretKeySpec(encodedKey, 0, encodedKey.length, “AES”); When you try to call it without new, the compiler thinks it might be a method you’ve defined inside that class, hence your error message.

Why does a byte only have 0 to 255?

Strictly speaking, the term “byte” can actually refer to a unit with other than 256 values. It’s just that that’s the almost universal size. From Wikipedia: Historically, a byte was the number of bits used to encode a single character of text in a computer and it is for this reason the basic addressable element …

Read more