Get binary size of particular String JAVA -


how binary size of string(for example string s = "ababa") in bits(not bytes).

get bytes, mutiply 8...

"xxx".getbytes().length * 8; 

edit: merging answer of jon skeet, it's important specify encoding, otherwise return size using system's default encoding, , that's not want know. know size using encoding, use:

 "xxx".getbytes(encoding).length * 8; 

encoding being "utf-8", "ascii", or whatever want use.


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -