## McAfee Interview Question for SDE1s

• 0

Country: India
Interview Type: In-Person

Comment hidden because of low score. Click to expand.
2
of 4 vote

8= 00000000 00000000 00000000 00001000
~8 = 11111111 11111111 11111111 11110111
we are assigning it in integer hence most significant bit (MSB)is the sign bit
bcz MSB is 1 hence it is treated as -ve no.
when u try to print it then before printing compiler will take 2's complement hence it becomes :
2's complement of (~8)=9
2's complement of 11111111 11111111 11111111 11110111 is 00000000 00000000 00000000 00001000 +1 = 1001 = 9

Comment hidden because of low score. Click to expand.
0

output will be -9, as compiler will take 2's complement and put a '-' sign in front of it.

Comment hidden because of low score. Click to expand.
1
of 1 vote

~ operator is, by definition, the operator to negate all bits, so it's the most appropriate answer.
FFFF is 16 bits, Xor with 0xFFFFFFFF would work

Comment hidden because of low score. Click to expand.
0
of 0 vote

Question is to negate each bit ,i.e 1000 should become 0111

Comment hidden because of low score. Click to expand.
0
of 0 vote

the operator is nothing but eg:-) if input is 8 then (8+1)*(-1) would get the ~ result.. correct me if its wrong:)

Comment hidden because of low score. Click to expand.
1
of 1 vote

It is not that way, actually (~) means compimenting or inverting the bits
eg:
6 ---> 0110
~6 --->1001

but system while accessing this from memory looks at the MSB('1'001) and thinks this as negative number, since system stores the negative number in 2's compliment it decodes it to get the number as (-7)
since -7 will be stored as 1001 in 2's compliment form

7 ---> 0111
-7 :
compliment of 7+1==> 1000+1==> 1001(ACTUAL BINARY STORAGE OF -7)

this is true concept :)

Comment hidden because of low score. Click to expand.
0
of 2 vote

the answer must b -9

Comment hidden because of low score. Click to expand.
0
of 0 vote

first of all, its output will be -9. (not 9)
if we take int is of 1 byte, then 8= 0000 1000
its ~, ~8=1111 0111
now compiler sees, oh, its MSB is 1, so it must be negative number. So in order to print it, I will take 2's compliment of this binary combination, find its decimal equivalent, put negative sign before it, and print it, That's it !
decimal equivalent of 1111 0111= -(2's comp of 1111 0111)
= -(0000 1001)
= -(9)

Comment hidden because of low score. Click to expand.
0

The output must be -9.

Comment hidden because of low score. Click to expand.
-1
of 1 vote

what is the question?

Comment hidden because of low score. Click to expand.
-1
of 1 vote

ideone.com/u5udnP does this answer your question.Basically two's complement is used to represent negative numbers.

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.