Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

r_misc.c File Reference

#include <stdio.h>
#include "r_misc.h"

Go to the source code of this file.


Functions

int ulong_size (unsigned long l)
unsigned long r_hex_str_to_long (char *src, int hex_digits)
int r_sprintf_long_to_hex (char *dest, unsigned long lsrc, int bytes, int pad)

Function Documentation

unsigned long r_hex_str_to_long char *    src,
int    hex_digits
 

Definition at line 31 of file r_misc.c.

00032 {
00033     unsigned long   res = 0;
00034     char          * cp;
00035     int             nib, digs;
00036 
00037     if ( hex_digits <= 0 || hex_digits > 8 )
00038         return 0;
00039 
00040     for ( digs = hex_digits, cp = src; digs > 0; digs--, cp++ )
00041     {
00042         if ( (*cp >= '0') && (*cp <= '9') )
00043             nib = *cp - '0';
00044         else if ( (*cp >= 'a') && (*cp <= 'f') )
00045             nib = *cp - 'a' + 10;
00046         else if ( (*cp >= 'A') && (*cp <= 'F') )
00047             nib = *cp - 'A' + 10;
00048         else
00049         {
00050             fprintf( stderr, "r_hex_str_to_long: invalid input string <%8s>\n",
00051                      src );
00052             return 0;
00053         }
00054 
00055         res = (res << 4) + (nib & 0xf);
00056     }
00057 
00058     return res;
00059 }

int r_sprintf_long_to_hex char *    dest,
unsigned long    lsrc,
int    bytes,
int    pad
 

---------------------------------------------------------------------- sprintf_long_to_hex - write hex chars to a string

return number of hex pairs written (should equal bytes) ----------------------------------------------------------------------

Definition at line 77 of file r_misc.c.

00083 {
00084     static char hexstring[] = "0123456789ABCDEF";
00085 
00086     unsigned char   ub;
00087     char          * cp = dest;
00088     int             posn, size, ret;
00089 
00090     if ( (bytes <= 0) || (bytes > 4) )
00091     {
00092         *cp = '\0';
00093         return 0;
00094     }
00095 
00096     size = ulong_size( lsrc );
00097 
00098     if ( (size < bytes) && !pad )       /* use size if we avoid padding  */
00099         ret = size;
00100     else
00101         ret = bytes;
00102 
00103     for ( posn = ret-1; posn >= 0; posn-- )
00104     {
00105         /* write one hex pair for this byte */
00106         ub = ( lsrc >> (posn << 3) ) & 0xff;            /* current ubyte */
00107         *cp++ = hexstring[(ub>>4) & 0xf];               /* upper nibble  */
00108         *cp++ = hexstring[ ub     & 0xf];               /* lower nibble  */
00109     }
00110 
00111     *cp = '\0';
00112 
00113     return ret;
00114 }

int ulong_size unsigned long    l [static]
 

Definition at line 118 of file r_misc.c.

References l.

Referenced by r_sprintf_long_to_hex().

00119 {
00120     if ( l & 0xff000000 )
00121         return 4;
00122 
00123     if ( l & 0xff0000 )
00124         return 3;
00125 
00126     if ( l & 0xff00 )
00127         return 2;
00128 
00129     return 1;
00130 }
 

Powered by Plone

This site conforms to the following standards: