public static int numBytes ( String val ) { BigInteger bInt = new BigInteger ( val ) ; int bytes = 0 ; while ( ! bInt . equals ( BigInteger . ZERO ) ) { bInt = bInt . shiftRight ( 8 ) ; ++ bytes ; } if ( bytes == 0 ) ++ bytes ; return bytes ; }
Calculate the number of bytes need to encode the number