-1
I’m making a particular app, I literally scoured the internet and I couldn’t find a way to count the number of bits of a particular phrase, someone can help me.
-1
I’m making a particular app, I literally scoured the internet and I couldn’t find a way to count the number of bits of a particular phrase, someone can help me.
3
You just need to know the number of bytes and multiply by 8. For example:
System.out.println("teste".getBytes().length * 8); //40
1
Knowing that each sentence character has 8 bits just do this:
String str = "Algum texto";
int numDeBits = str.length * 8;
I don’t know if this is the java syntax but anything leaves a comment that I try to fix.
What if the text is encoded in utf-8? There may be characters that occupy more than 8 bits.
in case will occupy 9 dai ne?
accented characters can increase the size of bytes in a string, even with the same number of characters, so it is best to count the number of bytes in the string.
ah then the answer from below is correct.
Browser other questions tagged java
You are not signed in. Login or sign up in order to post.
What if the text is encoded in utf-8? There may be characters that occupy more than 8 bits.
– Woss
Anderson, so the "getBytes()" and not the String size directly.
– Júlio Neto
In fact, my fault.
– Woss