Dark Bit Factory & Gravity

PROGRAMMING => C / C++ /C# => Topic started by: Stonemonkey on May 30, 2007

Title: SAR?
Post by: Stonemonkey on May 30, 2007
Is there any way to do SAR without resorting to asm?

Cheers,
Fryer.
Title: Re: SAR?
Post by: Jim on May 30, 2007
If you're working with signed values it does arithmetic shifts automatically.
ie
Code: [Select]
#include <stdio.h>

int main(void)
{
  int a=0x80000000;
  a = a >> 16;
  printf("%d %08X\n", a, a);
  return 0;
}
gives
Code: [Select]
-32768 0xFFFF8000

Jim
Title: Re: SAR?
Post by: Stonemonkey on May 30, 2007
DOH! Thanks Jim.