//NAME: BinaryOperations.c
//
//PURPOSE: To confirm some of the questions I have about C syntax involving
//         bit shifts, etc.
//
#include<stdio.h>

void main(){

  unsigned long X;
  unsigned long Y;
  unsigned long MaxDelta, MaxConst, Mask;
  unsigned int  BitMask;
  unsigned char SkyMode;
  unsigned char InterpMode;
  unsigned char ApplyBPM;

  X = 4;
  Y = 2;
  
  Mask     = ~(0xFFFFFFFF << X);
  MaxDelta = Y*(1<<(X-1));
  MaxConst = (~(0xFFFFFFFF << (Y+1))) << 18;

  printf("X        = %08X = %d\n", X, X);
  printf("Y        = %08X = %d\n", Y, Y);
  printf("MaxDelta = %08X = %d\n", MaxDelta, MaxDelta);
  printf("Mask     = %08X = %d\n", Mask, Mask);
  printf("MaxConst = %08X = %d\n", MaxConst, MaxConst);

  //Here is the processing argument mask that will be handed to the 
  //STARE firmware as a command argument
  BitMask    = 0x00000C21;
  ApplyBPM   = (BitMask & 0x0000000F);
  SkyMode    = (BitMask & 0x000000F0) >> 4;
  InterpMode = (BitMask & 0x00000F00) >> 8; 
 
  printf("Bad Pixel Mask value %08X = %d\n", ApplyBPM, ApplyBPM);
  printf("Sky Mode value       %08X = %d\n", SkyMode, SkyMode);
  printf("Interpolation value  %08X = %d\n", InterpMode, InterpMode);

  //Bit shifts
  BitMask = 0x01;
  printf("\n\rAbout to shift 0x01 to the left");
  for (X=0;X<8;++X){
    printf("%d %08X\n\r", X, BitMask << X);
  }
 
  printf("\n\rAbout to shift 0xC0 to the right");
  BitMask = 0xC0;
  for (X=0;X<7;++X){
    printf("%d %08X\n\r", X, BitMask >> X);
  }

}
