How to get a size of String in 64 bits(not bytes)in big endian order)?
I have never done this kind of operations in Java. Thanks for any help : ).
How to get a size of String in 64 bits(not bytes)in big endian order)?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Java works internally always using BigEndian order even if the platform like x86 uses LittleEndian.
In Java 64bit values are stored in the
longdata type.Now the final question is what you want to measure. In a String you can count the number of characters, or the number of bytes the String takes when encoding it using a specified encoding (e.g UTF-8, UTF-16, ISO-8859-1, …).
Assuming you want to count the number of characters in a String and you want to get the number as a 64bit number you can use the following code:
If you want to write
charCountinto a file or into a network connection you can use DataOutputStream for getting a BigEndian representation: