Alexandre Lision | 8af73cb | 2013-12-10 14:11:20 -0500 | [diff] [blame] | 1 | .\" |
| 2 | .\" Copyright 1992 by Jutta Degener and Carsten Bormann, Technische |
| 3 | .\" Universitaet Berlin. See the accompanying file "COPYRIGHT" for |
| 4 | .\" details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. |
| 5 | .\" |
| 6 | .PU |
| 7 | .TH BITTER 1 |
| 8 | .SH NAME |
| 9 | bitter, sweet \(em code-generators for packing bits |
| 10 | .SH SYNOPSIS |
| 11 | bitter < input > output |
| 12 | .br |
| 13 | sweet < input > output |
| 14 | .SH "DESCRIPTION" |
| 15 | Bitter and sweet are two filters which turn a description of the |
| 16 | form |
| 17 | .nf |
| 18 | name number-of-bits |
| 19 | name number-of-bits |
| 20 | ... |
| 21 | .nf |
| 22 | into code. |
| 23 | .PP |
| 24 | Bitter generates code that packs the specified bits from their |
| 25 | variables into an array of unsigned char referenced by an |
| 26 | advancing pointer c. |
| 27 | .PP |
| 28 | Sweet generates code that unpacks the specified bits from an array |
| 29 | of unsigned char referenced by a mutable pointer c into the |
| 30 | named variables. |
| 31 | .\" .SH OPTIONS |
| 32 | .\" .SH "RETURN VALUE" |
| 33 | .\" .SH ERRORS |
| 34 | .SH EXAMPLES |
| 35 | .nf |
| 36 | % cat in |
| 37 | amaretto 1 |
| 38 | banana 2 |
| 39 | cherry 3 |
| 40 | strawberry 4 |
| 41 | vanilla 15 |
| 42 | walnut 15 |
| 43 | |
| 44 | % bitter < in |
| 45 | *c++ = ((amaretto & 0x1) << 7) |
| 46 | | ((banana & 0x3) << 5) |
| 47 | | ((cherry & 0x7) << 2) |
| 48 | | ((strawberry >> 2) & 0x3); |
| 49 | *c++ = ((strawberry & 0x3) << 6) |
| 50 | | ((vanilla >> 9) & 0x3F); |
| 51 | *c++ = ((vanilla >> 1) & 0xFF); |
| 52 | *c++ = ((vanilla & 0x1) << 7) |
| 53 | | ((walnut >> 8) & 0x7F); |
| 54 | *c++ = walnut & 0xFF; |
| 55 | |
| 56 | % sweet < in |
| 57 | amaretto = (*c >> 7) & 0x1; |
| 58 | banana = (*c >> 5) & 0x3; |
| 59 | cherry = (*c >> 2) & 0x7; |
| 60 | strawberry = (*c++ & 0x3) << 2; |
| 61 | strawberry |= (*c >> 6) & 0x3; |
| 62 | vanilla = (*c++ & 0x3F) << 9; |
| 63 | vanilla |= (*c++ & 0xFF) << 1; |
| 64 | vanilla |= (*c >> 7) & 0x1; |
| 65 | walnut = (*c++ & 0x7F) << 8; |
| 66 | walnut |= *c++; |
| 67 | .SH NOTES |
| 68 | This is a quick hack for the gsm_encode() and gsm_decode() routines. |
| 69 | .SH BUGS |
| 70 | Please direct bug reports to jutta@cs.tu-berlin.de and cabo@cs.tu-berlin.de. |