You are not logged in. Please login at www.codechef.com to post your questions!

×

# binary operation

 0 int x= 6 & -6 ; then x= 2 how does the bitwise operation take place ? ANd how in -6 represented in binary form ? asked 19 Dec '12, 22:55 11●1●2 accept rate: 0%

 4 May be the link above already helped you . But to focus exactly on your question I am posting an answer . Six is represented as 110 in base 2 . That's simple right . It can changed back into decimal form by : 0 * 2^0 + 1 * 2^1 + 1 * 2^2 . Also note that there are preceding or leading zeroes in the binary representation of 6 . So exact representation is 000......000110 For representation of a negative number , just represent the number as if the negative sign is not there . Then subtract one from it . Remember you don't need a representation of negative 0 , as negative 0 and positive zero is the same thing . So subtracting 1 is always possible . After subtraction take the bitwise complement of the number . Now you have the representation of the negative number . So for -6 we have 0000.....00110 ( ignoring the sign ) Then subtract one to get , 0000.....00101 Then take bitwise complement to get , 1111...111010 The bitwise operations happens exactly as you would expect them , just doing the operation A op B for the i'th bit in A and i'th bit in B and storing the result in i'th bit in result . answered 20 Dec '12, 11:56 12.4k●47●107●171 accept rate: 12%
 0 Perhaps this could help. Take a look at the second answer: it'll make things clear. answered 19 Dec '12, 23:45 76●2●7 accept rate: 0%
 0 int(16 bits) 6 --> 0000000000000110 -6 --> 1111111111111010 (2's complement of(6)) (0000000000000110) AND(&)(1111111111111010) ans is 2 --> 0000000000000010 answered 20 Dec '12, 21:55 0★p_onkar 1●1 accept rate: 0%
 toggle preview community wiki:
Preview

### Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×184
×1

question asked: 19 Dec '12, 22:55

question was seen: 1,195 times

last updated: 20 Dec '12, 22:00