bit wise operator and octal help

Author: JAVANewbs Jul 29, 2004 10:23 AM

I tried to do this problem,

System.out.println(010|4);

and I thought it's six but it's actually 12.

Why is it outcome is 12?

I read the answer, it is because 010 is octal but how to tells if it is octal or hex or binary?

[344 byte] By [JAVANewbs] at [2007-9-30 14:13:59]
# 1
If the number begins with 0, it is octal, if it starts with 0x, it is hexadecimal.
Lacek at 2007-7-5 1:24:18 > top of Java-index,Administration Tools,Sun Connection...
# 2
In what sinerio it would be a binary 010?
JAVANewbs at 2007-7-5 1:24:18 > top of Java-index,Administration Tools,Sun Connection...
# 3
Only when you write 2, 02, 0x2, '\u0002', 1+1, or something like that.
jsalonen at 2007-7-5 1:24:18 > top of Java-index,Administration Tools,Sun Connection...
# 4
Ox02 is hex.... Please explain more..
JAVANewbs at 2007-7-5 1:24:18 > top of Java-index,Administration Tools,Sun Connection...
# 5
Yes, 2 is a hexadecimal digit, so "0x02" is a valid hexadecimal integer literal in the Java programming language.
jsalonen at 2007-7-5 1:24:18 > top of Java-index,Administration Tools,Sun Connection...
# 6
Are you answering in what secenerio the case is binary? or you just randoming answering with your knowledge?
JAVANewbs at 2007-7-5 1:24:18 > top of Java-index,Administration Tools,Sun Connection...
# 7

Sorry for the confusion:Let walk from the beginning...

I tried to do this problem,

System.out.println(010|4);

and I thought it's six but it's actually 12.

Why is it outcome is 12?

I read the answer, it is because 010 is octal but how to tells if it is octal or hex or binary?

Hex is represented by ox

Oct is represented by 0

and what about binary?

JAVANewbs at 2007-7-5 1:24:18 > top of Java-index,Administration Tools,Sun Connection...
# 8
Ah, so that's the problem. You can't write constants in binary, only in hex, octal, and decimal.
jsalonen at 2007-7-5 1:24:18 > top of Java-index,Administration Tools,Sun Connection...