Results 1 to 6 of 6
Thread: System.out.println(040|343);
- 06-26-2010, 10:17 AM #1
Member
- Join Date
- Jun 2010
- Posts
- 2
- Rep Power
- 0
- 06-26-2010, 10:48 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,601
- Blog Entries
- 7
- Rep Power
- 17
Any integer starting with a zero (0) introduces an octal representation of the number so 040 == 32 in decimal. The vertical bar (|) is the bitwise or operator, so 032 | 343 in binary is: 100000 | 101011001 == 101111001 which is 375 in decimal. I don't know where they got 345 as an answer from ...
kind regards,
Jos
- 06-26-2010, 11:20 AM #3
Senior Member
- Join Date
- Apr 2010
- Location
- Belgrade, Serbia
- Posts
- 278
- Rep Power
- 4
With small program I get "375"I checked that
System.out.println(040|343); prints "345"
when you have octal number you can convert it to binary number by number. Every octal number consist of 3 binary numbers ( 2 ^ 3 = 8 ).Java Code:public class Bitwise { public static void main(String[] args) { System.out.println(040 | 343); } }
So how convert 40 to binary?
4 = 100 ( 1 * 2 ^ 2 + 0 * 2 ^ 1 + 0 * 2 ^ 0 )
0 = 000 ( 0 * 2 ^ 2 + 0 * 2 ^1 + 0 * 2 ^ 0)
Then you have 40 in binary 100000.
in decimal:
100000 = (1 * 2 ^ 5 + 0 * 2 ^ 4 + 0 * 2 ^ 3 + 0 * 2 ^ 2 + 0 * 2 ^ 1 + 0 * 2 ^ 0 ) = 32
and finally you have (32 | 343).
- 06-26-2010, 01:30 PM #4
Member
- Join Date
- Jun 2010
- Posts
- 2
- Rep Power
- 0
Thanks to both of you above.
Sorry for the typo.. its "375"
- 06-26-2010, 06:49 PM #5
When one a person ever use bitwise comparison in practical applications?
EDIT: I'd be a bit chagrined if my imminent boss asked me for the result fromat an interview lol.Java Code:System.out.println(040|343)
Last edited by Lil_Aziz1; 06-26-2010 at 08:00 PM.
"Experience is what you get when you don't get what you want" (Dan Stanford)
"Rise and rise again until lambs become lions" (Robin Hood)
- 06-26-2010, 10:26 PM #6
Senior Member
- Join Date
- Apr 2010
- Location
- Belgrade, Serbia
- Posts
- 278
- Rep Power
- 4
It's very good to use bitwise operators in many occasions.When one a person ever use bitwise comparison in practical applications?
For example if you have device with 100.000 characteristic, it's cheaper to work with bits.
100.000 characterictics (on/off) implemented with bits is like working with 100.000 / 8 = 12.500.
Program is faster, but is difficult to implement.
Bitwise operators is a connection with low level languages (asembly languague).
Similar Threads
-
Println VS system.out.println
By ccie007 in forum New To JavaReplies: 2Last Post: 05-20-2010, 08:52 AM -
difference between system.out.println() & out.println()
By wickedrahul9 in forum Advanced JavaReplies: 5Last Post: 10-18-2008, 11:06 PM -
System.out.println
By Sniper-X in forum Advanced JavaReplies: 10Last Post: 05-05-2008, 03:41 PM -
System.out.println
By sunjavaboy in forum Advanced JavaReplies: 3Last Post: 03-22-2008, 01:30 AM -
Help me with system.out.println
By baltimore in forum New To JavaReplies: 1Last Post: 07-31-2007, 08:30 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks