1 /*
2 bitfill.c, Copyright (C) 2001-2003 Joe Laffey
3
4 $Revision: 1.7 $
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #else
25 #include "myTypes.h"
26 #endif
27
28 #include "bitfill.h"
29
30
31 /* This will fill in numBits bits with ones into an uint32. */
32 /* The fill starts on the left and moves toward the right like this: */
33 /* 11111111000000000000000000000000 */
34 /* The caller must be sure numBits is between 0 and 32 inclusive */
bitfill_from_left(uint32 numBits)35 uint32 bitfill_from_left( uint32 numBits )
36 {
37 uint32 myVal = 0;
38 register int i;
39
40 /* fill up the bits by adding ones so we have numBits ones */
41 for(i = 0; i< numBits; i++)
42 {
43 myVal = myVal >> 1;
44 myVal |= 0x80000000;
45 }
46
47 return myVal;
48 }
49
50
51
52 /* This will fill in numBits bits with ones into an uint32. */
53 /* The fill starts on the right and moves toward the right like this: */
54 /* 00000000000000000000000011111111 */
55 /* The caller must be sure numBits is between 0 and 32 inclusive */
bitfill_from_right(uint32 numBits)56 uint32 bitfill_from_right( uint32 numBits )
57 {
58 uint32 myVal = 0;
59 register int i;
60
61 /* fill up the bits by adding ones so we have numBits ones */
62 for(i = 0; i< numBits; i++)
63 {
64 myVal = myVal << 1;
65 myVal |= 1;
66 }
67
68 return myVal;
69 }
70