This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!See this thread for details.
Big Moose Saloon
 Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies Register / Login Win a copy of Refactoring for Software Design Smells: Managing Technical Debt this week in the OO, Patterns, UML and Refactoring forum!

# Urgent Help

bala_chocos
Ranch Hand

Joined: Aug 28, 2000
Posts: 48
hi
Q5:Given two int variables initialized as follows:
int a=63;// bit pattern //////
int b=4;// bit pattern 000100
what is the value of a&b.
a).63
b).4
c).null
d).0
schandu999
Greenhorn

Joined: Feb 07, 2002
Posts: 9
63= 111111111111111111111 (bin)
& (binary & operator)
4= 00000000000000000100 (bin)
------------------------------
000000000000000000100 = 4
as 1&1=1
1&0=0
0&1=0
0&0=0
bala_chocos
Ranch Hand

Joined: Aug 28, 2000
Posts: 48
hi champak
how are you converting 63 into binary numbers
iam in problem
kannan_al
Greenhorn

Joined: Sep 09, 2000
Posts: 4
hi friend,
To convert 63(decimal) to a binary number(in 2's Complement):
63 = 0011 1111

= 1*2^5+1*2^4+1*2^3+1*2^2+1*2^1+1*2^0
= 63

hope, you got it.
kannan.
Vishakha Ahuja
Ranch Hand

Joined: Sep 13, 2000
Posts: 191
It's very easy to convert a decimal number to binary....
Just divide the given +ve decimal number by 2. Again divide the quotient with 2 repeatedly until you get quotient as zero.
Then collect the remainders (which is either 1 or 0) and line them up in the reverse order i.e. right to left. Add zero's to fill up the remaining places.
Example 1:
2)63(31 2)31(15 2)15(7 2)7(3 2)3(1 2)1(0
62 30 14 6 2 0
--- --- --- -- -- --
1 1 1 1 1 1
so: 63 = 0011 1111
Example 2:
2)4(2 2)2(1 2)1(0
4 2 0
-- -- --
0 0 1
so:4 = 0000 0100
Vishakha Ahuja
Ranch Hand

Joined: Sep 13, 2000
Posts: 191
Sorry about the apperance of division in the above reply, I tried some formatting to make it look like division (in maths text book)
But, you see all my spaces have been collapsed....... Hope the above makes sense.
bala_chocos
Ranch Hand

Joined: Aug 28, 2000
Posts: 48
hi
still u are confusing
champak told me like
63=11111111
but vishak telling like this
63=00111111

Rong Chen
Ranch Hand

Joined: Aug 07, 2000
Posts: 30
63 should be 0011 1111b
but, guys, it's SCJP, isn't it?
softie
Ranch Hand

Joined: Aug 29, 2000
Posts: 41
Hi Bala,
a = 63 = 0011 1111
b = 4 = 0000 0100
a&b =4 = 0000 0100
Thats as simple as that.
Cheers,
Softie
Stephanie Grasson
Ranch Hand

Joined: Jun 14, 2000
Posts: 347
bala_chocos,
vishak is right.
63 decimal = 00111111 binary.
When you convert to binary, the same principles apply as in decimal numbers.
There is nothing in the hundredes position, a 6 in the tens position and a 3 in the ones position.
So we get
(6 * (10^1)) + (3 * (10^0)) =
(6 * 10) + (3 * 1) = 63.
The same logic applies for binary, but now instead of going by powers of 10 we go by powers of 2. Instead of having ones, tens, hundreds, thousands, etc. positions, we have ones, twos, fours, eights, sixteens, etc. positions.
So, getting back to the decimal number 63. In binary we have:
0 in the sixty-fours position
1 in the thirty-twos position
1 in the sixteens position
1 in the eights position
1 in the fours position
1 in the twos position
1 in the ones position
So:
(1 * (2^5)) +
(1 * (2^4)) +
(1 * (2^3)) +
(1 * (2^2)) +
(1 * (2^1)) +
(1 * (2^0)) =
(1 * 32) + (1 * 16) + (1 * 8) + (1 * 4) + (1 * 2) + (1 * 1) = 63;
00111111 binary = 63 decimal
Hope this helps.
Stephanie
Ira Jain
Ranch Hand

Joined: Sep 06, 2000
Posts: 70
Thank you Vishakha and Stephanie for explaining how to convert decimal numbers into binary numbers so nicely .It has really cleared up by fundas.
Thanks
Ira
------------------

I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com

subject: Urgent Help