# Bisewise and Binary, Help please

• 09-21-2013, 07:59 PM
Dai
Bisewise and Binary, Help please
Hello, so I need to use the use bisewise operators and have in the end 1's and 2's as a result but as a binary, now I had tested so I know that the result it's 1's and 2's, however when I use .toBinaryString it doest output binary numbers, I also tested with other numbers and it does work, but not for 1's and 2's, any idea why? I have below the output of the program, thank you
Code:

```public class TestBitwise {         public static void main(String[] args) {                                 int i = 1;                 Integer y = 1;                 int x = y & i;                 System.out.println (Integer.toBinaryString(x));                 //byte byte1 = 16;                 //System.out.println(x);                                 int i1 = 1;                 Integer y1 = 1;                 int x1 = y1 << i1;                 System.out.println (Integer.toBinaryString(x1));                 //System.out.println(x1);                                 int i2 = 1;                 Integer y2 = 0;                 int x2 = y2 ^ i2;                 System.out.println (Integer.toBinaryString(x2));                 //System.out.println(x2);                                 int i3 = 2;                 Integer y3 = 2;                 int x3 = y3 | i3;                 System.out.println (Integer.toBinaryString(x3));                 //System.out.println(x3);                                 int i4 = 0;                 Integer y4 = 1;                 int x4 = y4 >> i4;                 System.out.println (Integer.toBinaryString(x4));                 //System.out.println(x4);                                 int i5 = 1;                 Integer y5 = 1;                 int x5 = y5 << i5;                 System.out.println (Integer.toBinaryString(x5));                 //System.out.println(x5);         } }```
output of the program is not binary
1
10
1
10
1
10
• 09-21-2013, 08:12 PM
AndrewM16921
Re: Bisewise and Binary, Help please
I assume you mean "bitwise" not "bisewise" ?

That output is binary and is the correct answers for each operation you are performing. What are you expecting the output to be?

110 = 12
210 = 102

1.
1 and 1 = 1
00000001
00000001 AND
00000001

2.
1 << 1 = 210 = 102
00000001
00000001 <<
00000010

3.
1 xor 0 = 1
00000001
00000000 XOR
00000001

4.
210 or 210 = 102 or 102 = 210 = 102
00000010
00000010 OR
00000010

5.
1 >> 0 = 1
00000001
00000000 >>
00000001
• 09-21-2013, 08:17 PM
jim829
Re: Bisewise and Binary, Help please
Looks like binary to me. Do you understand binary?

Regards,
Jim
• 09-21-2013, 08:23 PM
Dai
Re: Bisewise and Binary, Help please
LOL you are right, I was using a website to check my answer and I guess I was looking at the wrong thing, but thank you for let me know that my code is correct ;)