Bitwise Operators
- & –> If both operands are true, then the result will be true.
- Ι –> If at least one arg is true, then the result is true.
- ∧ ( XOR ) –> If both args are different the result is true.
- s.o.p ( true & false ) ; // false
- s.o.p ( true / false ) ; // true
- s.o.p ( 4 8 5 ) ; // 4
- s.o.p ( 1/5 ) ; // 5
- s.o.p ( 4 Λ 5 ) ; // 1
Bitwise Complement Operators ( ~ )
We can apply this operator only for integral datatype but not for boolean types.
- s.o.p ( ~ true ) ; // compile time error
- s.o.p ( ~ 4 ) ; // 5
Negative numbers are represented in 2’s complement form
MSB—-> represent sign bit
0 means +ve
1 means -ve
Boolean Complement Operator ( ! )
- s.o.p ( ! true ) ; // false
- s.o.p ( ! false ) ; // true
- s.o.p ( ! 4 ) ; // compile time error
Note:- &, !, ^ ==> Applicable for boolean and integral types. ~ ==> Applicable only for integral types. ! ==> Applicable only for boolean types. |
Hello! I am Narayanaswamy founder and admin of narayanatutorial.com. I have been working in the IT industry for more than 12 years. NarayanaTutorial is my web technologies blog. My specialties are Java / J2EE, Spring, Hibernate, Struts, Webservices, PHP, Oracle, MySQL, SQLServer, Web Hosting, Website Development, and IAM(ForgeRock) Specialist
I am a self-learner and passionate about training and writing. I am always trying my best to share my knowledge through my blog.