int main(int argc, char** argv) { unsigned long int num; puts("Enter the number:"); scanf("%lu",&num); printf("%lu",Foo(num)); // Виклик функції PrintBinary(num); // Друк (2 код) аргумента PrintBinary(Foo(num)); // Друк (2 код) результату return 0; }
int main(int argc, char** argv) { unsigned long int num; puts("Enter the number:"); scanf("%ld",&num); printf("%ld",Foo(num)); // Виклик ф-ції Foo PrintBinary(num); // Друк (2 код) аргумента PrintBinary(Foo(num)); // Друк (2 код) результату return 0; }
int main(int argc, char** argv) { unsigned long int num; puts("Enter the number:"); scanf("%lu",&num); printf("%lu",Foo(num)); // Виклик ф-ції Foo PrintBinary(num); PrintBinary(Foo(num)); return 0; }
uint8_t TestRun (uint32_t data, uint8_t mode, GolayCW * encodeLookupTable, uint32_t * decodeLookUpTable) { uint8_t i; uint32_t error_mask_arr[] = {0x00, 0x01,0x03,0x07, 0x0f}; // Initial values for the error masks (1, 2 or 3 bits errors) uint32_t error_mask; // Current Error Mask GolayCW CodeWord1; GolayCW CodeWord2; CodeWord1.CodeWord = data; // Set the data for the two. CodeWord2.CodeWord = data; // Choose the encoding mode between LookUp and On-The-Fly if (mode == LOOKUP_TEST) { EncodeLT (GOLAY_24, &CodeWord1, encodeLookupTable); } else { Encode(GOLAY_24, &CodeWord1); } // Storing the correct codeword for future checks. CodeWord2.CodeWord = CodeWord1.CodeWord; // For every error generated by 1, 2 or 3 bits... for(i = 1; i <= 3; i++) { for (error_mask = error_mask_arr[i]; error_mask<0x800000; error_mask=NextBitPermutation(error_mask)) { // ...we inject the error in the codeword CodeWord1.CodeWord = CodeWord2.CodeWord ^ error_mask; // Choose the decoding mode between LookUp and On-The-Fly if (mode == LOOKUP_TEST) { DecodeLT (GOLAY_24, &CodeWord1, decodeLookUpTable); } else { Correction (GOLAY_24, &CodeWord1); } // If the saved codeword and the corrected one are difference there has been an error. if(CodeWord2.CodeWord ^ CodeWord1.CodeWord) { printf ("Mask: %x Something went wrong. This is the difference between what we got and the original:\n", error_mask); PrintBinary(CodeWord2.CodeWord ^ CodeWord1.CodeWord); return TEST_FAILED; } } } return TEST_SUCCESFUL; }
void TrafficDump(CDemoReader& reader, bool trafficStats) { InitCommandNames(); std::vector<unsigned> trafficCounter(NETMSG_LAST, 0); int frame = 0; int cmdId = 0; while (!reader.ReachedEnd()) { netcode::RawPacket* packet; packet = reader.GetData(3.402823466e+38f); if (packet == NULL) continue; assert(packet->data[0]<NETMSG_LAST); trafficCounter[packet->data[0]] += packet->length; const unsigned char* buffer = packet->data; char buf[16]; // FIXME: cba to look up how to format numbers with iostreams sprintf(buf, "%06d ", frame); std::cout << buf; const int cmd = (unsigned char)buffer[0]; switch (cmd) { case NETMSG_AICOMMAND: std::cout << "AICOMMAND: Playernum: " << (unsigned)buffer[3]; std::cout << " Length: " << (unsigned)packet->length; std::cout << " AI id: " << (unsigned)buffer[4]; std::cout << " UnitId: " << *((short*)(buffer + 5)); cmdId = *((int*)(buffer + 7)); std::cout << " CommandId: " << GetCommandName(cmdId) << "(" << cmdId << ")"; std::cout << " Options: " << (unsigned)buffer[11]; std::cout << " Parameters:"; for (unsigned short i = 12; i < packet->length; i += 4) { std::cout << " " << *((float*)(buffer + i)); } std::cout << std::endl; break; case NETMSG_AICOMMANDS: { std::cout << "AICOMMANDS: Playernum: " << (unsigned)buffer[3]; std::cout << " Length: " << (unsigned)packet->length; std::cout << " AI id: " << (unsigned)buffer[4]; std::cout << " Pair: " << (unsigned)buffer[5]; unsigned int sameid = *((unsigned int*)(buffer + 6)); std::cout << " SameID: " << sameid; unsigned int sameopt = (unsigned)buffer[10]; std::cout << " SameOpt: " << sameopt; unsigned short samesize = *((unsigned short*)(buffer + 11)); std::cout << " SameSize: " << samesize; short uidc = *((short*)(buffer + 13)); std::cout << " UnitIDCount: " << uidc; for (unsigned int i = 0; i < uidc; ++i) { std::cout << " " << *((short*)(buffer + 15 + i * 2)); } short cidc = *((short*)(buffer + 15 + uidc * 2)); int startp = 15 + uidc * 2 + 2; std::cout << " CmdIDCount: " << cidc; for (unsigned int i = 0; i < cidc; ++i) { if (sameid == 0) { std::cout << " " << *((unsigned int*)(buffer + startp)); startp += 4; } if (sameopt == 0xFF) { std::cout << " " << (unsigned)buffer[startp]; startp += 1; } if (sameopt == 0xFFFF) { std::cout << " " << *((unsigned short*)(buffer + startp)); startp += 2; } } std::cout << std::endl; break; } case NETMSG_PLAYERNAME: std::cout << "PLAYERNAME: Playernum: " << (unsigned)buffer[2] << " Name: " << buffer+3 << std::endl; break; case NETMSG_SETPLAYERNUM: std::cout << "SETPLAYERNUM: Playernum: " << (unsigned)buffer[1] << std::endl; break; case NETMSG_QUIT: std::cout << "QUIT" << std::endl; break; case NETMSG_STARTPLAYING: std::cout << "STARTPLAYING" << std::endl; break; case NETMSG_STARTPOS: std::cout << "STARTPOS: Playernum: " << (unsigned)buffer[1] << " Team: " << (unsigned)buffer[2] << " Readyness: " << (unsigned)buffer[3] << std::endl; break; case NETMSG_SYSTEMMSG: std::cout << "SYSTEMMSG: Player: " << (unsigned)buffer[3] << " Msg: " << (char*)(buffer+4) << std::endl; break; case NETMSG_CHAT: std::cout << "CHAT: Player: " << (unsigned)buffer[2] << " Msg: " << (char*)(buffer+4) << std::endl; break; case NETMSG_KEYFRAME: std::cout << "KEYFRAME: " << *(int*)(buffer+1) << std::endl; ++frame; if (*(int*)(buffer+1) != frame) { std::cout << "keyframe mismatch!" << std::endl; } break; case NETMSG_NEWFRAME: std::cout << "NEWFRAME" << std::endl; ++frame; break; case NETMSG_PLAYERINFO: std::cout << "NETMSG_PLAYERINFO: Player:" << (int)buffer[1] << " Ping: " << *(uint16_t*)&buffer[6] << std::endl; break; case NETMSG_LUAMSG: { std::cout << "LUAMSG length:" << packet->length << " Player:" << (unsigned)buffer[3] << " Script: " << *(uint16_t*)&buffer[4] << " Mode: " << (unsigned)buffer[6] << " Msg: "; PrintBinary(&packet->data[7], packet->length); std::cout << std::endl; break; } case NETMSG_TEAM: std::cout << "TEAM Playernum:" << (int)buffer[1] << " Action:"; switch (buffer[2]) { case TEAMMSG_GIVEAWAY: std::cout << "GIVEAWAY"; break; case TEAMMSG_RESIGN: std::cout << "RESIGN"; break; case TEAMMSG_TEAM_DIED: std::cout << "TEAM_DIED"; break; case TEAMMSG_JOIN_TEAM: std::cout << "JOIN_TEAM"; break; default: std::cout << (int)buffer[2]; } std::cout << " Parameter:" << (int)buffer[3] << std::endl; break; case NETMSG_COMMAND: std::cout << "COMMAND Playernum:" << (int)buffer[3] << " Size: " << *(unsigned short*)(buffer+1) << std::endl; if (*(unsigned short*)(buffer+1) != packet->length) std::cout << " packet length error: expected: " << *(unsigned short*)(buffer+1) << " got: " << packet->length << std::endl; break; case NETMSG_SELECT: std::cout << "NETMGS_SELECT: Playernum: " << (unsigned)buffer[3]; std::cout << " Length: " << (unsigned)packet->length; std::cout << " Unit IDs:"; for (unsigned short i = 4; i < packet->length; i += 2) { std::cout << " " << *((short*)(buffer + i)); } std::cout << std::endl; break; case NETMSG_GAMEOVER: std::cout << "NETMSG_GAMEOVER" << std::endl; break; case NETMSG_MAPDRAW: std::cout << "NETMSG_MAPDRAW" << std::endl; break; case NETMSG_PATH_CHECKSUM: std::cout << "NETMSG_PATH_CHECKSUM" << std::endl; break; case NETMSG_INTERNAL_SPEED: std::cout << "NETMSG_INTERNAL_SPEED" << std::endl; break; case NETMSG_PLAYERLEFT: std::cout << "NETMSG_PLAYERLEFT" << std::endl; break; case NETMSG_GAMEDATA: std::cout << "NETMSG_GAMEDATA" << std::endl; break; case NETMSG_CREATE_NEWPLAYER: std::cout << "NETMSG_CREATE_NEWPLAYER" << std::endl; break; case NETMSG_GAMEID: std::cout << "NETMSG_GAMEID" << std::endl; break; case NETMSG_RANDSEED: std::cout << "NETMSG_RANDSEED" << std::endl; break; case NETMSG_SHARE: std::cout << "NETMSG_SHARE: Playernum: " << (unsigned)buffer[1]; std::cout << " Team: " << (unsigned)buffer[2]; std::cout << " ShareUnits: " << (unsigned)buffer[3]; std::cout << " Metal: " << *(float*)(buffer + 4); std::cout << " Energy: " << *(float*)(buffer + 8); std::cout << std::endl; break; case NETMSG_CCOMMAND: std::cout << "NETMSG_CCOMMAND: " << std::endl; break; case NETMSG_PAUSE: std::cout << "NETMSG_PAUSE: Player " << (unsigned)buffer[1] << " paused: " << (unsigned)buffer[2] << std::endl; break; case NETMSG_SYNCRESPONSE: std::cout << "NETMSG_SYNCRESPONSE: " << std::endl; break; case NETMSG_DIRECT_CONTROL: std::cout << "NETMSG_DIRECT_CONTROL: " << std::endl; break; case NETMSG_SETSHARE: std::cout << "NETMSG_SETSHARE: " << std::endl; break; default: std::cout << "MSG: " << cmd << std::endl; } delete packet; } // how many times did each message appear for (unsigned i = 0; i != trafficCounter.size(); ++i) { if (trafficStats && trafficCounter[i] > 0) std::cout << "Msg " << i << ": " << trafficCounter[i] << std::endl; } }