Author Topic: SAR?  (Read 339 times)

0 Members and 1 Guest are viewing this topic.

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1215
  • Karma: 92
    • View Profile
SAR?
« on: May 30, 2007 »


Is there any way to do SAR without resorting to asm?

Cheers,
Fryer.

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5098
  • Karma: 380
    • View Profile
Re: SAR?
« Reply #1 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
Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1215
  • Karma: 92
    • View Profile
Re: SAR?
« Reply #2 on: May 30, 2007 »
DOH! Thanks Jim.