BigDecimal manipulation in java

Does BigDecimal support bit support? If so, can anyone provide a good tutorial on this?

If not, what is the best method for dividing a BigDecimal variable by degrees 2?

+4
source share
2 answers

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

+5
source

I think you mean BigInteger here. BigDecimal uses a decimal representation for floating point values, so it is not suitable for processing bits.

BigInteger has left and right shift operations using .shiftLeft() and .shiftRight() for multiplications / divisions into two levels respectively, so you can use this.

It also has operations such as .bitCount() , .bitLength() .{clear,set}Bit() , .and() , .or() , .andNot() and some others. No bitwise, however, as that makes no sense.

+7
source

Source: https://habr.com/ru/post/1491849/


All Articles