source: trunk/WRF.COMMON/WRFV2/external/io_grib1/MEL_grib1/set_bytes.c @ 2756

Last change on this file since 2756 was 11, checked in by aslmd, 14 years ago

spiga@svn-planeto:ajoute le modele meso-echelle martien

File size: 579 bytes
Line 
1#include <stdio.h>
2#include "isdb.h"
3
4void set_bytes(long in, int numbytes, char *out)
5{
6  int i;
7  long tmp;
8
9  tmp = abs(in);
10
11  for (i=0; i < numbytes; i++)
12    {
13      out[numbytes-1-i] = (tmp << (sizeof(long) - (i+1))*BYTE_BIT_CNT) 
14                                 >> (sizeof(long) - 1)*BYTE_BIT_CNT;
15    }
16  if ( in < 0 ) out[0] |= 0x0080;
17}
18
19
20void set_bytes_u(unsigned long in, int numbytes, unsigned char *out)
21{
22  int i;
23
24  for (i=0; i < numbytes; i++)
25    {
26      out[numbytes-1-i] = (in << (sizeof(unsigned long) - (i+1))*BYTE_BIT_CNT) 
27                                 >> (sizeof(unsigned long) - 1)*BYTE_BIT_CNT;
28    }
29}
Note: See TracBrowser for help on using the repository browser.