MyReads Flashcards

1
Q

Bitwise XOR (^)

A

It returns bit by bit XOR of input values, i.e, if corresponding bits are different, it gives 1, else it gives 0.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

2’s complement

A
  • invert all bits and add 1 bit
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
byte
short
int
long
float
double
boolean
char
A

byte: Byte data type is an 8-bit signed two’s complement integer.

Short: Short data type is a 16-bit signed two’s complement integer.

int: Int data type is a 32-bit signed two’s complement integer.
long: Long data type is a 64-bit signed two’s complement integer.
float: Float data type is a single-precision 32-bit IEEE 754 floating point.
double: double data type is a double-precision 64-bit IEEE 754 floating point.
boolean: boolean data type represents one bit of information.
char: char data type is a single 16-bit Unicode character.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Bitwise OR (|)

A

It returns bit by bit OR of input values, i.e, if either of the bits is 1, it gives 1, else it gives 0.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Bitwise AND (&)

A

It returns bit by bit AND of input values, i.e, if both bits are 1, it gives 1, else it gives 0.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
a = 0011 1100
b = 0000 1101
a&b
a|b
a^b
~a
A

a = 0011 1100
b = 0000 1101
—————–
a&b = 0000 1100

a|b = 0011 1101

a^b = 0011 0001

~a = 1100 0011

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Remove last bit ?

A

Remove last bit A&(A-1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Sum of Two Integers

A
int getSum(int a, int b) {
    return b==0? a:getSum(a^b, (a&amp;b)<<1); //be careful about the terminating condition;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Missing Number:

Given an array containing n distinct numbers taken from 0, 1, 2, …, n, find the one that is missing from the array

A

Loop:
ret ^= i;
ret ^= nums[i];

return ret^=nums.size();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Count 1 bits

A

Integer.bitCount();
x%2==1 and x = x&raquo_space;1
do until 0 - x & (x-1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Turn off only most significant bit

A

do -1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Retrieve the Right most bit

A

%2 or &1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly