L
lancer6238
Hi all,
I'm trying to write a program that extracts the first k bits of 64-bit
double values, given 2^k (which I've defined as size). Here, I use the
example that k = 3.
For example, 101001...011 would return 5, since the first 3 bits are
101.
#include <stdio.h>
#include <math.h>
#define size 8
#define NBITS 64 // number of bits in the datatype
int main()
{
double var, nvar;
unsigned int shift = 0;
int k;
var = pow(2, 63) + pow(2, 61);
k = (int)log2(size);
nvar = var>>(NBITS-k);
printf("nvar = %lf\n", nvar);
return 0;
}
However, I get the error "invalid operands to binary >>". What is
wrong with my program?
Thank you.
Regards,
Rayne
I'm trying to write a program that extracts the first k bits of 64-bit
double values, given 2^k (which I've defined as size). Here, I use the
example that k = 3.
For example, 101001...011 would return 5, since the first 3 bits are
101.
#include <stdio.h>
#include <math.h>
#define size 8
#define NBITS 64 // number of bits in the datatype
int main()
{
double var, nvar;
unsigned int shift = 0;
int k;
var = pow(2, 63) + pow(2, 61);
k = (int)log2(size);
nvar = var>>(NBITS-k);
printf("nvar = %lf\n", nvar);
return 0;
}
However, I get the error "invalid operands to binary >>". What is
wrong with my program?
Thank you.
Regards,
Rayne