lbitbits.c
Go to the documentation of this file.
00001 #include "f2c.h"
00002 #ifdef __cplusplus
00003 extern "C" {
00004 #endif
00005 
00006 #ifndef LONGBITS
00007 #define LONGBITS 32
00008 #endif
00009 
00010  integer
00011 #ifdef KR_headers
00012 lbit_bits(a, b, len) integer a, b, len;
00013 #else
00014 lbit_bits(integer a, integer b, integer len)
00015 #endif
00016 {
00017         /* Assume 2's complement arithmetic */
00018 
00019         unsigned long x, y;
00020 
00021         x = (unsigned long) a;
00022         y = (unsigned long)-1L;
00023         x >>= b;
00024         y <<= len;
00025         return (integer)(x & ~y);
00026         }
00027 
00028  integer
00029 #ifdef KR_headers
00030 lbit_cshift(a, b, len) integer a, b, len;
00031 #else
00032 lbit_cshift(integer a, integer b, integer len)
00033 #endif
00034 {
00035         unsigned long x, y, z;
00036 
00037         x = (unsigned long)a;
00038         if (len <= 0) {
00039                 if (len == 0)
00040                         return 0;
00041                 goto full_len;
00042                 }
00043         if (len >= LONGBITS) {
00044  full_len:
00045                 if (b >= 0) {
00046                         b %= LONGBITS;
00047                         return (integer)(x << b | x >> LONGBITS -b );
00048                         }
00049                 b = -b;
00050                 b %= LONGBITS;
00051                 return (integer)(x << LONGBITS - b | x >> b);
00052                 }
00053         y = z = (unsigned long)-1;
00054         y <<= len;
00055         z &= ~y;
00056         y &= x;
00057         x &= z;
00058         if (b >= 0) {
00059                 b %= len;
00060                 return (integer)(y | z & (x << b | x >> len - b));
00061                 }
00062         b = -b;
00063         b %= len;
00064         return (integer)(y | z & (x >> b | x << len - b));
00065         }
00066 #ifdef __cplusplus
00067 }
00068 #endif


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:55:56