source: buchla-68k/orig/GP/PRBITS.C@ 0170798

Last change on this file since 0170798 was 3ae31e9, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Imported original source code.

  • Property mode set to 100755
File size: 1.2 KB
Line 
1/*
2 =============================================================================
3 prbits.c -- print groups of bits from a number
4 Version 1 -- 1988-09-21 -- D.N. Lynx Crowe
5 =============================================================================
6*/
7
8#include "stdio.h"
9#include "stddefs.h"
10
11/*
12 =============================================================================
13 prbits(n, l, r, gs) -- print selected groups of bits of 'n'
14
15 'n' number to print bits from
16 'r' rightmost bit to use starting with the LSB
17 'l' leftmost bit to use starting with the LSB
18 'gs' bits in each group starting on the right
19 =============================================================================
20*/
21
22prbits(n, l, r, gs)
23register long n;
24register int l, r, gs;
25{
26 register char *bp;
27 register int i;
28 char buf[66];
29
30 if (( l < 0) OR ( l > 31) OR
31 ( r < 0) OR ( r > 31) OR
32 (gs < 1) OR (gs > 32) OR
33 ( r > l))
34 return;
35
36 bp = &buf[65];
37 *bp-- = '\0';
38
39 for (i = r; i < (l + 1); i++) {
40
41 if ((i NE 0) AND (0 EQ (i % gs)))
42 *bp-- = ' ';
43
44 if (n & (1L << i))
45 *bp-- = '1';
46 else
47 *bp-- = '0';
48 }
49
50 ++bp;
51
52 if (*bp EQ ' ')
53 ++bp;
54
55 while ('\0' NE (c = *bp++))
56 putchar(c);
57}
Note: See TracBrowser for help on using the repository browser.