I'm doing a certain application, I literally searched the internet and I did not find how I can count the number of bits of a certain phrase, can someone help me.
I'm doing a certain application, I literally searched the internet and I did not find how I can count the number of bits of a certain phrase, can someone help me.
You only need to know the number of bytes and multiply by 8. For example:
System.out.println("teste".getBytes().length * 8); //40
Knowing that each character of the sentence has 8 bits, just do this:
String str = "Algum texto";
int numDeBits = str.length * 8;
I do not know if this is the java syntax but anything leaves a comment I try to fix.