望各位帮忙看看,现在就想要答案,蟹蟹各位潜水专家,感谢解答,感谢回答,感谢解答。在“PUT YOUR CODE HERE”写内容,前面内容不要改动,按照要求来写。
// swap pairs of bits of a 64-bit value, using bitwise operators
#include <assert.h>
#include <stdint.h>
#include <stdlib.h>
// return value with pairs of bits swapped
uint64_t bit_swap(uint64_t value) {
// PUT YOUR CODE HERE
return 42;
}
// swap pairs of bits of a 64-bit value, using bitwise operators
#include <assert.h>
#include <stdint.h>
#include <stdlib.h>
// return value with pairs of bits swapped
uint64_t bit_swap(uint64_t value) {
uint64_t data = 0;
int a,b,m=0;
for(int i=0;i<32;i++)
{
a = value&1;
value = value>>1;
b = value&1;
value = value>>1;
m+=2;
if(b>0)
data |= (b<<m-2);
if(a>0)
data |= (a<<m-1);
}
return data;
}
// swap pairs of bits of a 64-bit value, using bitwise operators
#include <assert.h>
#include <stdint.h>
#include <stdlib.h>
#include<stdio.h>
// return value with pairs of bits swapped
uint64_t bit_swap(uint64_t value)
{
uint64_t a = (uint64_t)0x55555555555555555, b = (uint64_t)0xaaaaaaaaaaaaaaaa;
// printf("%llx\n", value);
// printf("%llx\n", a);
// printf("%llx\n", b);
a = value & a;
// printf("%llx\n", a);
b = value & b;
// printf("%llx\n", b);
return ((a << 1) | (b >> 1));
}
int main(int argc, char const *argv[])
{
printf("%llx\n", bit_swap((uint64_t)0x1111111111111111));
printf("%llx\n", bit_swap((uint64_t)0x1111888855553333));
return 0;
}