Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bit data type in Java

Tags:

java

c

struct

bit

I am writing a program, in Java, which need bit processing, and manipulations. But I could not find any "bit" level primitive datatype. Is there any way in Java to define "bit" datatype? In C/C++, we can tell compiler how many bits to allocate for variables storage as

struct bit {
    unsigned int value : 1;   // 1 bit to store value
};

How can I do same thing in Java?

like image 831
Saumesh Avatar asked Oct 17 '25 14:10

Saumesh


1 Answers

boolean or Boolean with true or false (or Boolean.TRUE / Boolean.FALSE). Both of which can be used with autoboxing and unboxing. There is also a BitSet for handling a vector of bits.

like image 165
Elliott Frisch Avatar answered Oct 19 '25 05:10

Elliott Frisch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!