Whats the reverse function of x XOR (x/2)? - bit-manipulation

Whats the reverse function of x XOR (x/2)?
Is there a system of rules for equation solving, similar to algebra, but with logic operators?

Suppose we have a number x of N bits. You could write this as:
b(N-1) b(N-2) b(N-3) ... b(0)
where b(i) is bit number i in the number (where 0 is the least significant bit).
x / 2 is the same as x shifted left 1 bit. Let's assume unsigned numbers. So:
x / 2 = 0 b(N-1) b(N-2) ... b(1)
Now we XOR x with x / 2:
x ^ (x / 2) = b(N-1)^0 b(N-2)^b(N-1) b(N-3)^b(N-2) ... b(0)^b(1)
Note that the rightmost bit (the most significant bit) of this is b(N-1)^0 which is b(N-1). In other words, you can get bit b(N-1) from the result immediately. When you have this bit, you can calculate b(N-2) because the second bit of the result is b(N-2)^b(N-1) and you already know b(N-1). And so on, you can compute all bits b(N-1) to b(0) of the original number x.

I can give you an algorithm in bits:
Assuming you have an array of n bits:
b = [b1 .. bn] // b1-bn are 0 or 1
The original array is:
x0 = b0
x1 = b1 ^ x0
x2 = b2 ^ x1
or in general
x[i] = b[i] ^ x[i-1]

Assume Y = X ^ (X / 2)
If you want to find X, do this
X = 0
do
X ^= Y
Y /= 2
while Y != 0
I hope it helps!

I know it's an old topic, but I stumbled upon the same question, and I found out a little trick. If you have n bits, instead of requiring n bits operations (like the answer by Jesper), you can do it with log2(n) number operations :
Suppose that y is equal to x XOR (x/2) at the beginning of the program, you can do the following C program :
INPUT : y
int i, x;
x = y;
for (i = 1; i < n; i <<= 1)
x ^= x >> i;
OUTPUT : x
and here you have the solution.
">>" is the right bit shift operation. For example the number 13, 1101 in binary, if shifted by 1 on the right, will become 110 in binary, thus 13 >> 1 = 6. x >> i is equivalent to x / 2^i (division in the integers, of course)
"<<" is the left bit shift operation (i <<= 1 is equivalent to i *= 2)
Why does it work ? Let's take as example n = 5 bits, and start with y = b4 b3 b2 b1 b0 (in binary : in the following x is written in binary also, but i is written in decimal)
Initialisation :
x = b4 b3 b2 b1 b0
First step : i = 1
x >> 1 = b4 b3 b2 b1 so we have
x = b4 b3 b2 b1 b0 XOR b3 b2 b1 b0 = b4 (b3^b4) (b2^b3) (b1^b2) (b0^b1)
Second step : i = 2
x >> 2 = b4 (b3^b4) (b2^b3) so we have
x = b4 (b3^b4) (b2^b3) (b1^b2) (b0^b1) XOR b4 (b3^b4) (b2^b3) = b4 (b3^b4) (b2^b3^b4) (b1^b2^b3^b4) (b0^b1^b2^b3)
Third step : i = 4
x >> 4 = b4 so we have
x = b4 (b3^b4) (b2^b3^b4) (b1^b2^b3^b4) (b0^b1^b2^b3) XOR b4 = b4 (b3^b4) (b2^b3^b4) (b1^b2^b3^b4) (b0^b1^b2^b3^b4)
Then i = 8, which is more than 5, we exit the loop.
And we have the desired output.
The loop has log2(n) iterations because i starts at 1 and is multiplied by 2 at each step, so for i to reach n, we have to do it log2(n) times.

Related

XOR programming puzzle advice

Given a long int x, count the number of values of a that satisfy the following conditions:
a XOR x > x
0 < a < x
where a and x are long integers and XOR is the bitwise XOR operator
How would you go about completing this problem?
I should also mentioned that the input x can be as large as 10^10
I have managed to get a brute force solution by iterating over 0 to x checking the conditions and incrementing a count value.. however this is not an optimal solution...
This is the brute force that I tried. It works but is extremely slow for large values of x.
for(int i =0; i < x; i++)
{
if((0 < i && i < x) && (i ^ x) > x)
count++;
}
long long NumberOfA(long long x)
{
long long t = x <<1;
while(t^(t&-t)) t ^= (t&-t);
return t-++x;
}
long long x = 10000000000;
printf("%lld ==> %lld\n", 10LL, NumberOfA(10LL) );
printf("%lld ==> %lld\n", x, NumberOfA(x) );
Output
10 ==> 5
10000000000 ==> 7179869183
Link to IDEOne Code
Trying to explain the logic (using example 10, or 1010b)
Shift x to the left 1. (Value 20 or 10100b)
Turn off all low bits, leaving just the high bit (Value 16 or 10000b)
Subtract x+1 (16 - 11 == 5)
Attempting to explain
(although its not easy)
Your rule is that a ^ x must be bigger than x, but that you cannot add extra bits to a or x.
(If you start with a 4-bit value, you can only use 4-bits)
The biggest possible value for a number in N-bits is 2^n -1.
(eg. 4-bit number, 2^4-1 == 15)
Lets call this number B.
Between your value x and B (inclusive), there are B-x possible values.
(back to my example, 10. Between 15 and 10, there are 5 possible values: 11, 12, 13, 14, 15)
In my code, t is x << 1, then with all the low bits turned off.
(10 << 1 is 20; turn off all the low bits to get 16)
Then 16 - 1 is B, and B - x is your answer:
(t - 1 - x, is the same as t - ++x, is the answer)
One way to look at this is to consider each bit in x.
If it's 1, then flipping it will yield a smaller number.
If it's 0, then flipping it will yield a larger number, and we should count it - and also all the combinations of bits to the right. That conveniently adds up to the mask value.
long f(long const x)
{
// only positive x can have non-zero result
if (x <= 0) return 0;
long count = 0;
// Iterate from LSB to MSB
for (long mask = 1; mask < x; mask <<= 1)
count += x & mask
? 0
: mask;
return count;
}
We might suspect a pattern here - it looks like we're just copying x and flipping its bits.
Let's confirm, using a minimal test program:
#include <cstdlib>
#include <iostream>
int main(int, char **argv)
{
while (*++argv)
std::cout << *argv << " -> " << f(std::atol(*argv)) << std::endl;
}
0 -> 0
1 -> 0
2 -> 1
3 -> 0
4 -> 3
5 -> 2
6 -> 1
7 -> 0
8 -> 7
9 -> 6
10 -> 5
11 -> 4
12 -> 3
13 -> 2
14 -> 1
15 -> 0
So all we have to do is 'smear' the value so that all the zero bits after the most-significant 1 are set, then xor with that:
long f(long const x)
{
if (x <= 0) return 0;
long mask = x;
while (mask & (mask+1))
mask |= mask+1;
return mask ^ x;
}
This is much faster, and still O(log n).

Deriving nth Gray code from the (n-1)th Gray Code

Is there a way to derive the 4-bit nth Gray code using the (n-1)th Gray code by using bit operations on the (n-1)th Gray Code?
For example the 4th Gray code is 0010. Now I want to get the 5th Gray Code, 0110, by doing bit operations on 0010.
Perhaps it's "cheating" but you can just pack a lookup table into a 64-bit constant value, like this:
0000 0 -> 1
0001 1 -> 3
0011 3 -> 2
0010 2 -> 6
0110 6 -> 7
0111 7 -> 5
0101 5 -> 4
0100 4 -> C
1100 C -> D
1101 D -> F
1111 F -> E
1110 E -> A
1010 A -> B
1011 B -> 9
1001 9 -> 8
1000 8 -> 0
FEDCBA9876543210 nybble order (current Gray code)
| |
V V
EAFD9B80574C2631 next Gray code
Then you can use shifts and masks to perform a lookup (depending on your language):
int next_gray_code(int code)
{
return (0xEAFD9B80574C2631ULL >> (code << 2)) & 15;
}
Alternatively, you can use the formula for converting from Gray to binary, increment the value, and then convert from binary to Gray, which is just n xor (n / 2):
int next_gray_code(int code)
{
code = code ^ (code >> 2);
code = code ^ (code >> 1);
code = (code + 1) & 15;
return code ^ (code >> 1);
}
What about the following?
t1 := XOR(g0, g1)
b0 := !XOR(g0, g1, g2, g3)
b1 := t1 & g2 & g3 + !t1 & !g2 & !g3
b2 := t1 & g2 & !g3
b3 := t1 & !g2 & !g3
n0 := XOR(b0, g0)
n1 := XOR(b1, g1)
n2 := XOR(b2, g2)
n3 := XOR(b3, g3)
The current gray code word is g3 g2 g1 g0 and the next code word is n3 n2 n1 n0. b3 b2 b1 b0 are the four bits which flip or not flip a bit in the code word to progress to the subsequent code word. Only one bit is changed between adjacent code words.

What does this expression calculate

Suppose X and Y are two positive integers and Y is a power of two. Then what does this expression calculate?
(X+Y-1) & ~(Y-1)
I found this expression appearing in certain c/c++ implementation of Memory Pool (X represents the object size in bytes and Y represents the alignment in bytes, the expression returns the block size in bytes fit for use in the Memory Pool).
&~(Y-1) where Y is a power of 2, zeroes the last n bits, where Y = 2n: Y-1 produces n 1-bits, inverting that via ~ gives you a mask with n zeroes at the end, anding via bit-level & zeroes the bits where the mask is zero.
Effectively that produces a number that is some multiple of Y's power of 2.
It can maximally have the effect of subtracting Y-1 from the number, so add that first, giving (X+Y-1) & ~(Y-1). This is a number that's not less than X, and is a multiple of Y.
It gives you the next Y-aligned address of current address X.
Say, your current address X is 0x10000, and your alignment is 0x100, it will give you 0x10000. But if your current address X is 0x10001, you will get "next" aligned address of 0x10100.
This is useful in the scenario that you want your new object always to be aligned to blocks in memory, but not leaving any block unused. So you want to know what is the next available block-aligned address.
Why don't you just try some input and observe what happens?
#include <iostream>
unsigned compute(unsigned x, unsigned y)
{
return (x + y - 1) & ~(y - 1);
}
int main()
{
std::cout << "(x + y - 1) & ~(y - 1)" << std::endl;
for (unsigned x = 0; x < 9; ++x)
{
std::cout << "x=" << x << ", y=2 -> " << compute(x, 2) << std::endl;
}
std::cout << "----" << std::endl;
std::cout << "(x + y - 1) & ~(y - 1)" << std::endl;
for (unsigned x = 0; x < 9; ++x)
{
std::cout << "(x=" << x << ", y=2) -> " << compute(x, 2) << std::endl;
}
return 0;
}
Live Example
Output:
First set uses x in [0, 8] and y is constant 2. Second set uses x in [0, 8] and y is constant 4.
(x + y - 1) & ~(y - 1)
x=0, y=2 -> 0
x=1, y=2 -> 2
x=2, y=2 -> 2
x=3, y=2 -> 4
x=4, y=2 -> 4
x=5, y=2 -> 6
x=6, y=2 -> 6
x=7, y=2 -> 8
x=8, y=2 -> 8
----
(x + y - 1) & ~(y - 1)
(x=0, y=2) -> 0
(x=1, y=2) -> 2
(x=2, y=2) -> 2
(x=3, y=2) -> 4
(x=4, y=2) -> 4
(x=5, y=2) -> 6
(x=6, y=2) -> 6
(x=7, y=2) -> 8
(x=8, y=2) -> 8
It's easy to see the output (i.e., result right of ->) is always a multiple of y such that the output is greater than or equal to x.
First I assume that X and Y are unsigned integers.
Let's have a look at the right part:
If Y is a power of 2, it is represented in binary by one bit to 1 and all the others to 0. Example 8 will be binary 00..01000.
If you substract 1 the highest bit will be 0 and all the bits to its right will become 1. Example 8-1= 7 and in binary 00..00111
If you ~ negate this number you will make sure that all highest bit (including the original one will turn to 1 and the lovest to 0. Example: ~7 will be 11..11000
Now if you do a binary AND (&) with any number, you will set to 0 all the lower bits, in our example, the 3 lower bits. THe resulting number is hence a multiple of Y.
Let's look at the left side:
We've already analysed Y-1. In our example we had 7, that is 00..00111
If you add this to any number, you make sure that the result is greater than or equal to Y. Example with 5: 5+7=12 so 00..01100 and example with 10: 10+7=17 so 00..10001
If you then perform the AND, you'll erase the lower bits. so in our example with 5, we come to 00..01000 = 8 and in our example with 10 we get 00..10000 16.
Conclusion, it's the smallest multiple of Y wich is greater or equal to X.
Let's break it down, piece by piece.
(X+Y-1) & ~(Y-1)
Let's suppose that X = 11 and Y = 16 in accordance with your rules and that the integers are 8 bits.
(11+16-1) & ~(16-1)
Do the Addition and Subtraction
(26) & ~(15)
Translate this into binary
(0001 1010) & ~(0000 1111)
~ means not or to invert the zeros and ones
(0001 1010) & (1111 0000)
& means only to take the bits that are both ones
0001 0000
convert back to decimal
16
other examples
X = 78, Y = 32 results in 96
X = 25, Y = 64 results in 64
X = 47, Y = 16 results in 48
So, it would seem to me that the purpose of this is to find lowest multiple of Y that is equal to or greater than X. This could be used for finding the start/end address of a block of memory, or it could be used for positioning items on the screen, or any number of other possible answers as well. But without context and possibly even a full code example. There's no guarantee.
(X+Y-1) & ~(Y-1)
x = 7 = 0b0111
y = 4 = 0b0100
x+y-1 = 0b1010
y-1 = 3 = 0b0011
~(y-1) = 0b1100
(x+y-1) & ~(y-1) = 0b1000 = 8
--
x = 12 = 0b1100
y = 2 = 0b0010
x+y-1 = 13 = 0b1101
y-1 = 1 = 0b0001
~(y-1) = 0b1110
(x+y-1) & ~(y-1) = 0b1100 = 12
(x+y-1) & ~(y-1) is the smallest multiple of y greater than or equal to x
It seems provides a specified alignment of a value for example of a memory address (for example when you want to get the next aligned address).
For example if you want that a memory address would be aligned at the paragraph bound you can write
( address + 16 - 1 ) & ~( 16 - 1 )
or
( address + 15 ) & ~15
or
( address + 15 ) & ~0xf
In this case all bits before 16 will be zeroed.
This part of expression
( address + alignment - )
is used for rounding.
and this part of expression
~( alignment - 1 )
is used to build a mask thet zeroes low bits.

challenging bit manipulation procedure

This question showed up on one of my teacher's old final exams. How does one even think logically about arriving at the answer?
I am familiar with the bit-manipulation operators and conversion between hex and binary.
int whatisthis(int x) {
x = (0x55555555 & x) + (0x55555555 & (x >>> 1));
x = (0x33333333 & x) + (0x33333333 & (x >>> 2));
x = (0x0f0f0f0f & x) + (0x0f0f0f0f & (x >>> 4));
x = (0x00ff00ff & x) + (0x00ff00ff & (x >>> 8));
x = (0x0000ffff & x) + (0x0000ffff & (x >>> 16));
return x;
}
Didn't you forget some left shifts?
x = ((0x55555555 & x) <<< 1) + (0x55555555 & (x >>> 1));
x = ((0x33333333 & x) <<< 2) + (0x33333333 & (x >>> 2));
snip...
This would then be the reversal of bits from left to right.
You can see that bits are moved together rather than one by one and this lead to a cost in O(log2(nbit))
(you invert 2^5=32 bits in 5 statements)
It might help you to rewrite the constants in binary to understand better how it works.
If there are no left shifts, then I can't help you because the additions will generate carry and I can't see any obvious meaning...
EDIT: OK, interesting, so this is for counting the number of bits set to 1 (also known as population count or popcount)... Here is a squeak Smalltalk quick test on 16 bits
| f |
f := [:x |
| y |
y := (x bitAnd: 16r5555) + (x >> 1 bitAnd: 16r5555).
y := (y bitAnd: 16r3333) + (y >> 2 bitAnd: 16r3333).
y := (y bitAnd: 16r0F0F) + (y >> 4 bitAnd: 16r0F0F).
y := (y bitAnd: 16r00FF) + (y >> 8 bitAnd: 16r00FF).
y].
^(0 to: 16rFFFF) detect: [:i | i bitCount ~= (f value: i)] ifNone: [nil]
The first statement handle each bit pairs. If no bit is set in the pair then it produce 00, if a single bit is set, it produces 01, if two bits are set, it produces 10.
00 -> 0+0 -> 00 = 0, no bit set
01 -> 1+0 -> 01 = 1, 1 bit set
10 -> 0+1 -> 01 = 1, 1 bit set
11 -> 1+1 -> 10 = 2, 2 bits set
So it count the number of bits in each pair.
The second statement handles group of 4 adjacent bits:
0000 -> 00+00 -> 0000 0+0=0 bits set
0001 -> 01+00 -> 0001 1+0=1 bits set
0010 -> 10+00 -> 0010 2+0=2 bits set
0100 -> 00+01 -> 0001 0+1=1 bits set
0101 -> 01+01 -> 0010 1+1=2 bits set
0110 -> 10+01 -> 0011 2+1=3 bits set
1000 -> 00+10 -> 0010 0+2=2 bits set
1001 -> 01+10 -> 0011 1+2=3 bits set
1010 -> 10+10 -> 0100 2+2=4 bits set
So, while the first step did replace each pair of bits by the number of bits set in this pair, the second did add this count in each pair of pair...
Next will handle each group of 8 adjacent bits, and sum the number of bits sets in two groups of 4...

Understanding Left and Right Bitwise shift on a 128-bit number

Artichoke101 asked this:
Lets say that I have an array of 4 32-bit integers which I use to store the 128-bit number
How can I perform left and right shift on this 128-bit number?"
My question is related to the answer Remus Rusanu gave:
void shiftl128 (
unsigned int& a,
unsigned int& b,
unsigned int& c,
unsigned int& d,
size_t k)
{
assert (k <= 128);
if (k > 32)
{
a=b;
b=c;
c=d;
d=0;
shiftl128(a,b,c,d,k-32);
}
else
{
a = (a << k) | (b >> (32-k));
b = (b << k) | (c >> (32-k));
c = (c << k) | (d >> (32-k));
d = (d << k);
}
}
void shiftr128 (
unsigned int& a,
unsigned int& b,
unsigned int& c,
unsigned int& d,
size_t k)
{
assert (k <= 128);
if (k > 32)
{
d=c;
c=b;
b=a;
a=0;
shiftr128(a,b,c,d,k-32);
}
else
{
d = (c << (32-k)) | (d >> k); \
c = (b << (32-k)) | (c >> k); \
b = (a << (32-k)) | (b >> k); \
a = (a >> k);
}
}
Lets just focus on one shift, the left shift say. Specifically,
a = (a << k) | (b >> (32-k));
b = (b << k) | (c >> (32-k));
c = (c << k) | (d >> (32-k));
d = (d << k);
How is this left shifting the 128-bit number? I understand what bit shifting is, << shifts bits left, (8-bit number) like 00011000 left shifted 2 is 01100000. Same goes for the right shift, but to the right. Then the single "pipe" | is OR meaning any 1 in either 32-bit number will be in the result.
How is a = (a << k) | (b >> (32-k)) shifting the first part (32) of the 128-bit number correctly?
This technique is somewhat idiomatic. Let's simplify to just a and b. We start with:
+----------+----------+
| a | b |
+----------+----------+
and we want to shift left some amount to obtain:
+----------+----------+
| a : | b : | c ...
+----------+----------+
|<--x-->| |
->|y |<-
So X is simply a << k. y is the k msbs of b, right-aligned in the word. You obtain that result with b >> (32-k).
So overall, you get:
a = x | y
= (a << k) | (b >> (32-k))
[Note: This approach is only valid for 1 <= k <= 31, so your code is actually incorrect.]
When the bits of a get shifted to the left, something has to fill in the space left over on the right end. Since a and b are conceptually adjacent to each other, the void left by shifting the bits of a gets filled by the bits that are shifted off the end of b. The expression b >> (32-k) computes the bits that get shifted off of b.
You need to remember that it is acceptable, in shifting, to "lose" data.
The simplest way to understand shifting is to imagine a window. For example, let us work on bytes. You can view a byte as:
0 0 0 0 0 0 0 0 a b c d e f g h 0 0 0 0 0 0 0 0
[ B ]
Now, shifting is just about moving this window:
0 0 0 0 0 0 0 0 a b c d e f g h 0 0 0 0 0 0 0 0
[ B >> 8 ]
[ B >> 7 ]
[ B >> 6 ]
[ B >> 5 ]
0 0 0 0 0 0 0 0 a b c d e f g h 0 0 0 0 0 0 0 0
[ B >> 4 ]
[ B >> 3 ]
[ B >> 2 ]
[ B >> 1 ]
0 0 0 0 0 0 0 0 a b c d e f g h 0 0 0 0 0 0 0 0
[ B << 1 ]
[ B << 2 ]
[ B << 3 ]
[ B << 4 ]
0 0 0 0 0 0 0 0 a b c d e f g h 0 0 0 0 0 0 0 0
[ B << 5 ]
[ B << 6 ]
[ B << 7 ]
[ B << 8 ]
0 0 0 0 0 0 0 0 a b c d e f g h 0 0 0 0 0 0 0 0
If you look at the direction of the arrows, you can think of it as having a fixed window and a moving content... just like your fancy mobile phone touch screen!
So, what is happening in the expression a = (a << k) | (b >> (32-k)) ?
a << k selects the 32 - k rightmost bits of a and move them toward the left, creating a space of k 0 on the right side
b >> (32-k) selects the k leftmost bits of b and move them toward the right, creating a space of 32 - k 0 on the left side
the two are merged together
Getting back to using byte-length bites:
Suppose that a is [a7, a6, a5, a4, a3, a2, a1, a0]
Suppose that b is [b7, b6, b5. b4, b3, b2, b1, b0]
Suppose that k is 3
The number represented is:
// before
a7 a6 a5 a4 a3 a2 a1 a0 b7 b6 b5 b4 b3 b2 b1 b0
[ a ]
[ b ]
// after (or so we would like)
a7 a6 a5 a4 a3 a2 a1 a0 b7 b6 b5 b4 b3 b2 b1 b0
[ a ]
[ b ]
So:
a << 3 does actually become a4 a3 a2 a1 a0 0 0 0
b >> (8 - 3) becomes 0 0 0 0 0 b7 b6 b5
combining with | we get a4 a3 a2 a1 a0 b7 b6 b5
rinse and repeat :)
Note that in the else case k is guaranteed to be 32 or less. So each part of your larger number can actually be shifted by k bits. However, shifting it either left or right makes the k higher/lower bits 0. To shift the whole 128bit number you need to fill these k bits with the bits "shifted out" of the neighboring number.
In the case of a left shift by k, the k lower bits of the higher number need to be filled with the k upper bits of the lower number. to get these upper k bits, we shift that (32bit) number right by 32-k bits and now we got those bits in the right position to fill in the zero k bits from the higher number.
BTW: the code above assumes that an unsigned int is exactly 32 bits. That is not portable.
To simplify, consider a 16-bit unsigned short, where we store the high and low bytes as unsigned char h, l respectively.
To simplify further, let's just shift it left by one bit, to see how that goes.
I'm writing it out as 16 consecutive bits, since that's what we're modelling:
[h7 h6 h5 h4 h3 h2 h1 h0 l7 l6 l5 l4 l3 l2 l1 l0]
so, [h, l] << 1 will be
[h6 h5 h4 h3 h2 h1 h0 l7 l6 l5 l4 l3 l2 l1 l0 0]
(the top bit, h7 has been rotated off the top, and the low bit is filled with zero).
Now let's break that back up into h and l ...
[h, l] = [h6 h5 h4 h3 h2 h1 h0 l7 l6 l5 l4 l3 l2 l1 l0 0]
=> h = [h6 h5 h4 h3 h2 h1 h0 l7]
= (h << 1) | (l >> 7)
etc.
my variant for logical left shift of 128 bit number in little endian environment:
typedef struct { unsigned int component[4]; } vector4;
vector4 shift_left_logical_128bit_le(vector4 input,unsigned int numbits) {
vector4 result;
if(n>=128) {
result.component[0]=0;
result.component[1]=0;
result.component[2]=0;
result.component[3]=0;
return r;
}
result=input;
while(numbits>32) {
numbits-=32;
result.component[0]=0;
result.component[1]=result.component[0];
result.component[2]=result.component[1];
result.component[3]=result.component[2];
}
unsigned long long temp;
result.component[3]<<=numbits;
temp=(unsigned long long)result.component[2];
temp=(temp<<numbits)>>32;
result.component[3]|=(unsigned int)temp;
result.component[2]<<=numbits;
temp=(unsigned long long)result.component[1];
temp=(temp<<numbits)>>32;
result.component[2]|=(unsigned int)temp;
result.component[1]<<=numbits;
temp=(unsigned long long)result.component[0];
temp=(temp<<numbits)>>32;
result.component[1]|=(unsigned int)temp;
result.component[0]<<=numbits;
return result;
}