Search code examples
javabigdecimal

BigDecimal bit manipulation in java


Does BigDecimal support bit manipulation? If yes, can someone please point to a good tutorial on this?

If no, what is the best method to divide a BigDecimal variable by powers of 2?


Solution

  • As the name suggests, a BigDecimal is stored in decimal representation. So the quickest way to divide by powers of 2 is ... to divide by powers of two. You can shift-left and shift-right, but only in base-10 (and even then it behaves differently from bit-shifts, because it can produce non-integer values).