codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
#include "stdio.h" typedef unsigned char uchar; uchar pack_tile (uchar ID, uchar passable) { if (ID < 128 && (passable == 0 || passable == 1)) return (ID << 1) + passable; else exit(1); /* There's no real error checking in C, so we're just gonna fail * the program if the values aren't good. */ } void read_tile (uchar packedID) { printf("Tile %d:\n", packedID); printf(" ID: %d\n", packedID >> 1); if (packedID & 1) printf(" passable\n"); else printf(" non-passable\n"); } int main (int argc, char *argv[]) { uchar t1 = 36; uchar t1_p = 1; // t1 is tile 1 ID valude t1_p determines whether it should be passable or not uchar t2 = 47; uchar t2_p = 0; uchar t3 = 127; uchar t3_p = 1; /* So, we'll just read back the packed data and it should print the exact values * that we declared and initialized. */ read_tile(pack_tile(t1, t1_p)); read_tile(pack_tile(t2, t2_p)); read_tile(pack_tile(t3, t3_p)); return 0; }
Private
[
?
]
Run code
Submit