VMWare Inc Interview Question for Software Engineers

• 0

Country: United States
Interview Type: Written Test

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

``````bool X86IsCanonicalAddress(void *a) {
void *b = 0xffff000000000000;
if ((a & b) == b)
return true;

if ((a ^ b) & b == b)
return true;

return false;
}``````

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

I think all you need to do for this one is isolate the high 16 bits to see if they are all 0 or 1.

``````bool X86IsCanonicalAddress(int a) {
// Return true if lowest 48 bits are equal and highest 16 bits are all 1 or all 0
// Assumes compiler treats int as unsigned 64bit and does arithmetic shifting

// Isolate the highest 16 bits.
// If all 1, result will be -1 due to arithmetic type shifting.
// If all 0, result is 0
int high16 = a >> 48;

if(high16 == -1 || high16 == 0) {
return true;
}

return false;
}``````

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

Can you please explain the code above?

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

Simple:

``````bool isCanonical(unsigned long long add) {

unsigned long long int mask = 0xFFFF000000000000;

}``````

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

``````BigInteger bigInt = new BigInteger(inputString, 2);
return  new BigInteger(binStr, 2);.shiftRight(48).equals(new BigInteger("1111111111111111", 2)) || bigInt.shiftRight(48).equals(new BigInteger("0000000000000000", 2));``````

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

I think the question might be missing a detail. According to the wiki, canonical address definition is like this:
"... the AMD specification requires that bits 48 through 63 of any virtual address must be copies of bit 47"

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.