Add some debug lines, and write the hex values as binary if it helps. (And it is best to use unsigned types with bit shifting.)
Code:
#include<stdio.h>
#define SEED 3254
unsigned int random()
{
static unsigned int reg=SEED;
unsigned int bit13, bit14;
unsigned int exor;
bit14=(reg|0x4000)>>14; // i am confused here
bit13=(reg|0x2000)>>13; exor=bit14^bit13;
printf("reg = %x, bit14 = %x, bit13 = %x\n", reg, bit14, bit13);
reg=reg<<1;
printf("reg = %x, bit14 = %x, bit13 = %x\n", reg, bit14, bit13);
reg=(reg|exor)&0x7fff; // and here
printf("reg = %x, bit14 = %x, bit13 = %x\n", reg, bit14, bit13);
return reg;
}
int main(void)
{
random();
return 0;
}
/* my output
reg = cb6, bit14 = 1, bit13 = 1
reg = 196c, bit14 = 1, bit13 = 1
reg = 196c, bit14 = 1, bit13 = 1
*/