Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 653
jobin Avatar asked Dec 12 '22 13:12

jobin


1 Answers

I think you mean BigInteger here. BigDecimal uses a decimal representation for floating point values, so it is not suited for bit manipulation.

BigInteger does have left and right shift operations with .shiftLeft() and .shiftRight() for multiplications/divisions by powers of two respectively, so you can use that.

It also has operations such as .bitCount(), .bitLength(), .{clear,set}Bit(), .and(), .or(), .andNot() and a few others. No bitwise not, though, since it does not make sense.

like image 143
fge Avatar answered Jan 02 '23 16:01

fge