0

Hi JavaExperts

I have done few program in Java using Bit wise AND OR operator... But Not getting the proper output or May be I am doing something wrong
Can any body explain why I am getting output

class Bit
{
   public static void main(String args[])
  {
    System.out.println(010|4);
   }
}

12 for the following code ,but how? plz. explain

Edited by mike_2000_17: Fixed formatting

6
Contributors
12
Replies
13
Views
9 Years
Discussion Span
Last Post by llemes4011
0

010 (decimal) is 1010 binary, 4 is 0100, or them together you get 1110 which is 14. Now I'm puzzled as well. Perhaps I need a cup of coffee.

0

10 = is an integer
010 = is an octal (base 8)

So 010 = 1000 in binary
1000
0100
------
1100 = 12

I think this is how it works at least :)

0

the best way to solve bitwise problem is write eveything in bits and perform the operation and after tat convert it into octal or decimal

0

tell this "WRONG!" to my JDK. Maybe it ll accept it. I won't.

public class ASD{
	public static void main (String [] args){
		System.out.println(21+21);
	}
}

C:\Users\HCL\Desktop>java ASD
42

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.