51 lines
803 B
C
51 lines
803 B
C
|
/* unsigned _HalveUnsArr(a,n)
|
||
|
*
|
||
|
* ARGUMENT
|
||
|
* unsigned a[];
|
||
|
* int n; number of digits
|
||
|
*
|
||
|
* DESCRIPTION
|
||
|
* Halves (Divides by 2) the number a.
|
||
|
*
|
||
|
* SIDE EFFECTS
|
||
|
* If the number is odd, discards the least significant bit.
|
||
|
*
|
||
|
* RETURNS
|
||
|
*
|
||
|
*
|
||
|
* AUTHOR
|
||
|
* Brugnoli Giugno 1992
|
||
|
*
|
||
|
* MODIFICATIONS
|
||
|
*
|
||
|
*/
|
||
|
|
||
|
#include <stdio.h>
|
||
|
#include "gm.h"
|
||
|
#include "gmsystem.h"
|
||
|
|
||
|
#include "gmsys1.h"
|
||
|
|
||
|
void _HalveUnsArr(a,n)
|
||
|
unsigned SHORT a[];
|
||
|
int n;
|
||
|
{
|
||
|
int i;
|
||
|
unsigned SHORT rem,qt;
|
||
|
unsigned long remup,ntbd;
|
||
|
|
||
|
rem=0;
|
||
|
|
||
|
if (n)
|
||
|
{
|
||
|
for (i=n-1;i>=0;i--)
|
||
|
{
|
||
|
remup=(long)rem<<BITSPERUI;
|
||
|
ntbd=(long)a[i]+remup;
|
||
|
qt=(unsigned SHORT)(ntbd / 2);
|
||
|
rem=(unsigned SHORT)(ntbd % 2);
|
||
|
a[i]=qt;
|
||
|
}
|
||
|
}
|
||
|
}
|