#include #include // for toupper #include #include #include #include #define BREAD ((unsigned char) 3) // 00000011 #define BREAD_BYTE 0 #define BREAD_OFFSET 0 #define MEAT ((unsigned char) 12) // 00001100 #define MEAT_BYTE 0 #define MEAT_OFFSET 2 #define TOMATO ((unsigned char) 48) // 00110000 #define TOMATO_BYTE 0 #define TOMATO_OFFSET 4 #define ONION ((unsigned char) 192) // 11000000 #define ONION_BYTE 0 #define ONION_OFFSET 6 #define CHEESE ((unsigned char) 3) // 00000011 #define CHEESE_BYTE 1 #define CHEESE_OFFSET 0 #define P1_COOKED ((unsigned char) 12) // 00001100 #define P1_COOKED_BYTE 1 #define P1_COOKED_OFFSET 2 #define P2_COOKED ((unsigned char) 48) // 00110000 #define P2_COOKED_BYTE 1 #define P2_COOKED_OFFSET 4 #define P3_COOKED ((unsigned char) 192) // 11000000 #define P3_COOKED_BYTE 1 #define P3_COOKED_OFFSET 6 #define CHILI ((unsigned char) 1) #define BACON ((unsigned char) 2) #define LETTUCE ((unsigned char) 4) #define PICKLE ((unsigned char) 8) #define CATSUP ((unsigned char) 16) #define MUSTARD ((unsigned char) 32) #define MAYO ((unsigned char) 64) #define SPICE_MUSTARD ((unsigned char) 128) #define HOT_SAUCE ((unsigned char) 1) #define SALT ((unsigned char) 2) #define PEPPER ((unsigned char) 4) char* meat_type[] = {"single", "double", "tripple"}; char* bread_type[] = {"no bun", "bun", "wheat bun", "toast"}; char* tomato_type[] = {"no tomato", "tomato", "grilled tomato"}; char* onion_type[] = {"no onion", "onion", "grilled onion"}; char* toppings_type[] = {"chili", "bacon", "lettuce", "pickle", "catsup", "mustard", "mayonaise", "spicy mustard", "hot sauce", "salt", "pepper"}; char* cooked_type[] = {"medium rare", "medium", "medium well", "well done"}; char* cheese_type[] = {"no cheese", "1 slice of cheese", "2 slices of cheese", "3 slices of cheese"}; void PrintBitArray(unsigned char* bit_array, int size) { int i, max, offset, shift; max = sizeof(unsigned char)*size*8 - 1; for (i = max; i >= 0; i--) { offset = i / 8; shift = i % 8; if ((bit_array[offset] >> shift) & 1) cout << "1"; else cout << "0"; } } unsigned char GetByte (unsigned char* bit_array, int i) { return bit_array[i]; } void PrintOrder(unsigned long o) { unsigned char b; int patties, cheese; b = GetByte((unsigned char*)(&o), BREAD_BYTE); cout << bread_type[((b & BREAD) >> BREAD_OFFSET) % 4]; b = GetByte((unsigned char*)(&o), MEAT_BYTE); patties = ((b & MEAT) >> MEAT_OFFSET) % 3; cout << ", " << meat_type[patties]; b = GetByte((unsigned char*)(&o), TOMATO_BYTE); cout << ", " << tomato_type[((b & TOMATO) >> TOMATO_OFFSET) % 3]; b = GetByte((unsigned char*)(&o), ONION_BYTE); cout << ", " << onion_type[((b & ONION) >> ONION_OFFSET) % 3]; b = GetByte((unsigned char*)(&o), CHEESE_BYTE); cheese = (b & CHEESE) >> CHEESE_OFFSET; if (cheese > patties + 1) cheese = 0; cout << ", " << cheese_type[cheese]; cout << ", patty 1: "; b = GetByte((unsigned char*)(&o), P1_COOKED_BYTE); cout << cooked_type[((b & P1_COOKED) >> P1_COOKED_OFFSET) % 4]; if (patties > 0) { cout << ", patty 2: "; b = GetByte((unsigned char*)(&o), P2_COOKED_BYTE); cout << cooked_type[((b & P2_COOKED) >> P2_COOKED_OFFSET) % 4]; if (patties > 1) { cout << ", patty 3: "; b = GetByte((unsigned char*)(&o), P3_COOKED_BYTE); cout << cooked_type[((b & P3_COOKED) >> P3_COOKED_OFFSET) % 4]; } } b = GetByte((unsigned char*)(&o), 2); if (b & CHILI) cout << ", chili"; if (b & BACON) cout << ", bacon"; if (b & LETTUCE) cout << ", lettuce"; if (b & PICKLE) cout << ", pickle"; if (b & CATSUP) cout << ", catsup"; if (b & MUSTARD) cout << ", mustard"; if (b & MAYO) cout << ", mayonaise"; if (b & SPICE_MUSTARD) cout << ", spicy mustard"; b = GetByte((unsigned char*)(&o), 3); if (b & HOT_SAUCE) cout << ", hot sauce"; if (b & SALT) cout << ", salt"; if (b & PEPPER) cout << ", pepper"; } void main (void) { unsigned long o; srand((unsigned)time( NULL )); for(int i=0; i < 2000; i++) { o = (rand() * rand() * rand()) % UINT_MAX; // cout << setw(15) << o << " : "; // PrintBitArray((unsigned char*)(&o), sizeof(unsigned long)); cout << endl; PrintOrder(o); cout << endl << endl; } }