Use bit shift to compute the total length needed instead of using Math.pow.