B
bobrics
Hi,
I am trying to understand what is wrong with my code. What I have below
is a part of a linear feedback shift register. But it's simplified to
the point where it does not matter. The main problem is bit masks and
endian notation, in my opinion.
If *lfsr is 0x80000000 and the value of temp_bitmask is 0x00000080,
then their bitwise AND should be all zeroes, isn't it? The debugger
prints out that the answer is 0x1 somehow, which 0x00000001. What is
wrong?
The target endianness is set automatically (currently little endian)
Thank you in advance!
#include <stdio.h>
#define INPUT_BIT_MASK 0x80000000
void main (void)
{
int i = 0;
unsigned int lfsr[] = 0x80000000;
unsigned int temp_bitmask;
temp_bitmask = INPUT_BIT_MASK;
temp_bitmask = temp_bitmask >> 28;
printf("the value of temp_bitmask is %d or %x\n", (unsigned int)
temp_bitmask, temp_bitmask);
printf("the value at *lfsr is %d or %x\n", *lfsr, *lfsr);
printf("the value of (temp_bitmask && *lfsr) is %d or %x\n",
(temp_bitmask && *lfsr), (temp_bitmask && *lfsr));
return 0;
}
I am trying to understand what is wrong with my code. What I have below
is a part of a linear feedback shift register. But it's simplified to
the point where it does not matter. The main problem is bit masks and
endian notation, in my opinion.
If *lfsr is 0x80000000 and the value of temp_bitmask is 0x00000080,
then their bitwise AND should be all zeroes, isn't it? The debugger
prints out that the answer is 0x1 somehow, which 0x00000001. What is
wrong?
The target endianness is set automatically (currently little endian)
Thank you in advance!
#include <stdio.h>
#define INPUT_BIT_MASK 0x80000000
void main (void)
{
int i = 0;
unsigned int lfsr[] = 0x80000000;
unsigned int temp_bitmask;
temp_bitmask = INPUT_BIT_MASK;
temp_bitmask = temp_bitmask >> 28;
printf("the value of temp_bitmask is %d or %x\n", (unsigned int)
temp_bitmask, temp_bitmask);
printf("the value at *lfsr is %d or %x\n", *lfsr, *lfsr);
printf("the value of (temp_bitmask && *lfsr) is %d or %x\n",
(temp_bitmask && *lfsr), (temp_bitmask && *lfsr));
return 0;
}