1 // 2 // bitfield.h - extract and set bit fields 3 // 4 // Written by Eryk Vershen 5 // 6 // Bitfields are not particularly transportable between big and little 7 // endian machines. Big endian machines lay out bitfields starting 8 // from the most significant bit of the (one, two or four byte) number, 9 // whereas little endian machines lay out bitfields starting from the 10 // least signifcant bit. 11 // 12 // These routines were written to support some bitfields in a disk 13 // data structure (partition map) whose original definition was on 14 // a big-endian machine. 15 // 16 // They only work on 32-bit values because I didn't need 16-bit support. 17 // The bits in the long word are numbered from 0 (least significant) to 18 // 31 (most significant). 19 // 20 21 /* 22 * Copyright 1996,1998 by Apple Computer, Inc. 23 * All Rights Reserved 24 * 25 * Permission to use, copy, modify, and distribute this software and 26 * its documentation for any purpose and without fee is hereby granted, 27 * provided that the above copyright notice appears in all copies and 28 * that both the copyright notice and this permission notice appear in 29 * supporting documentation. 30 * 31 * APPLE COMPUTER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE 32 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 33 * FOR A PARTICULAR PURPOSE. 34 * 35 * IN NO EVENT SHALL APPLE COMPUTER BE LIABLE FOR ANY SPECIAL, INDIRECT, OR 36 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 37 * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, 38 * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION 39 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 40 */ 41 42 #ifndef __bitfield__ 43 #define __bitfield__ 44 45 46 // 47 // Defines 48 // 49 50 51 // 52 // Types 53 // 54 55 56 // 57 // Global Constants 58 // 59 60 61 // 62 // Global Variables 63 // 64 65 66 // 67 // Forward declarations 68 // 69 uint32_t bitfield_set(uint32_t *bf, int base, int length, uint32_t value); 70 71 uint32_t bitfield_get(uint32_t bf, int base, int length); 72 73 #endif /* __bitfield__ */ 74