Bit Manipulation Flashcards

1
Q

Left Shift «

A

Eg: N«i (N: first operand, i: second operand)

Takes two numbers, left shifts the bits of the first operand, the second operand decides the number of places to shift. Or in other words left shifting an integer “x” with an integer “y” denoted as ‘(x«y)’ is equivalent to multiplying x with 2^y (2 raised to power y).

eg: lets take N=22; which is 00010110 in Binary Form.

  Now, if “N is left-shifted by 2” i.e N=N<<2 then N will become N=N*(2^2). Thus, N=22*(2^2)=88 which can be written as 01011000.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Right Shift&raquo_space;

A

Eg: N»i (N: first operand, i: second operand)

Takes two numbers, right shifts the bits of the first operand, the second operand decides the number of places to shift. In other words right shifting an integer “x” with an integer “y” denoted as ‘(x»y)‘ is equivalent to dividing x with 2^y.

eg: lets take N=32; which is 100000 in Binary Form.

 Now, if “N is right-shifted by 2” i.e N=N>>2 then N will become N=N/(2^2). Thus, N=32/(2^2)=8 which can be written as 1000.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

how much int 32 can represent

A

Integers come in several sizes: 8 bits, 16 bits, 32 bits, and 64 bits are the common choices. The size determines the number of integers that can be represented. For example, a 32-bit integer can represent 2^32 values.

An integer can be unsigned or signed. Unsigned integers represent only nonnegative values. A 32-bit unsigned integer can represent an integer between 0 and 2^32 – 1. Signed integers represent both negative and nonnegative values, with an equal number of each representable. A 32-bit signed integer can represent an integer between -2^31 and 2^31 – 1.

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