is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.
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.
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.
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.
<pre lang="java" line="1" title="CodeMonkey28074" class="run-this">public class BitwiseSquare {
- jasantunes November 24, 2010/**
* Simple multiplication using bitwise operators.
*/
public static int multiply(int a, int b) {
int product = 0;
while (a > 0) {
if ((a & 1) != 0)
product += b;
b = b << 1;
a = a >> 1;
}
return product;
}
/**
* This is better explained using an example. Example: 24 = 16+8 (bit 4th
* and 3rd) 24^2 = (16+8)^2 = 16^2 + 8^2 + 2x16x8 26^2 = (16+8+2)^2, using
* powers of 2. (16+8+2)^2 = 2*2+2 + 8*8+2*8*(2) + 16*16+2*16*(2+8) = 676
*/
public static int square(int a) {
int bitpos = 0;
int result0 = 0; // 16*16 + 8*8 + 2*2
int result1 = 0; // 2 + 2*8*(2) + 2x16x(2+8)
int temp = 0; // 2+8+16
while (a > 0) {
if ((a & 1) != 0) {
// 16^2 = (2^4)^2 = 2^(4+4)
int b = 1;
// b = 16 = 2^4
b = b << bitpos;
// result1 += 2 * b * temp;
result1 += multiply(b, temp) << 1;
temp += b;
// b = 16^2 = 2^(4+4)
b = b << bitpos;
result0 += b;
}
a = a >> 1;
bitpos++;
}
return result0 + result1;
}
public static void main(String[] args) throws java.lang.Exception {
for (String s : args) {
int val = Integer.parseInt(s);
System.out.println(val + "^2 = " + square(val));
}
}
}
</pre><pre title="CodeMonkey28074" input="yes">1 3 26</pre>