McAfee Interview Question for SDE1s


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

- Bajaj July 30, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

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

- nharryp March 31, 2014 | Flag
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

- Miguel Oliveira July 30, 2013 | Flag Reply
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

- gaurav.2897 July 30, 2013 | Flag Reply
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:)

- ram rs July 30, 2013 | Flag Reply
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 :)

- vishal August 01, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 2 vote

the answer must b -9

- vgstech July 30, 2013 | Flag Reply
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)

- P.S. Patel August 15, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

The output must be -9.

- Anita August 16, 2013 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

what is the question?

- ? July 30, 2013 | Flag Reply
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.

- aka July 30, 2013 | Flag Reply


Add a Comment
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.

Learn More

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.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More