Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the size of char[]?

Tags:

java

char

size

I'm making hash algorithm, the block of message is 512 bits. In C/C++ I can store in char[64], but Java char takes 2 bytes.

Question: 512 bits of information are char[32] or char[64]?

like image 583
ilja Avatar asked Feb 10 '23 06:02

ilja


1 Answers

Char is 16bit in Java. So char[32] should be enough for 512bits. I think using byte[64] is better though because everyone know a byte is 8 bits and char[32] makes the code harder to read. Also you don't store characters but bits.

like image 131
Veselin Davidov Avatar answered Feb 13 '23 05:02

Veselin Davidov