std::string NumConverter::ToOctal() { if (NumSys == oct) { return Val; } else { std::string s(""); if (NumSys == dec) { s = Val; int tmp = atoi(s.c_str()); char buf[32]; snprintf(buf, sizeof(buf), "%o", tmp); s = buf; } if (NumSys == bin) { s = BinToDec(Val); int tmp = atoi(s.c_str()); char buf[32]; snprintf(buf, sizeof(buf), "%o", tmp); s = buf; } if (NumSys == hex) { s = HexToDec(Val); int tmp = atoi(s.c_str()); char buf[32]; snprintf(buf, sizeof(buf), "%o", tmp); s = buf; } return s; } }
//-------------------------------------------------------------------------------------------------- int32_t le_hex_StringToBinary ( const char *stringPtr, ///< [IN] string to convert, terminated with '\0'. uint32_t stringLength, ///< [IN] string length uint8_t *binaryPtr, ///< [OUT] binary result uint32_t binarySize ///< [IN] size of the binary table ) { uint32_t idxString,idxBinary; if (2*binarySize+1 < stringLength) { LE_DEBUG("binary array (%u) is too small (%u)",binarySize, stringLength); return -1; } for(idxString=0,idxBinary=0; idxString<stringLength; idxString=idxString+2,idxBinary++) { char tmp[3]; tmp[0] = stringPtr[idxString]; tmp[1] = stringPtr[idxString+1]; tmp[2] = '\0'; binaryPtr[idxBinary] = HexToDec((unsigned const char*)tmp); } return idxBinary; }
wxString UnescapeHTML(const wxString& str) { wxWritableCharBuffer buf = str.char_str(wxConvUTF8); // Work around wxWritableCharBuffer's operator[] not being writable char *buffer = (char *)buf; size_t len = std::strlen(buffer); size_t j = 0; for (size_t i = 0; i < len; ++i, ++j) { if (buffer[i] == '%' && (len > i + 2)) { wxChar unesc = HexToDec(str.Mid(i + 1, 2)); if (unesc) { i += 2; buffer[j] = (char)unesc; } else { // If conversion failed, then we just add the escape-code // and continue past it like nothing happened. buffer[j] = buffer[i]; } } else { buffer[j] = buffer[i]; } } buffer[j] = '\0'; // Try to interpret the result as UTF-8 wxString result(buffer, wxConvUTF8); if (len > 0 && result.length() == 0) { // Fall back to ISO-8859-1 result = wxString(buffer, wxConvISO8859_1); } return result; }
int HexToDec(CString strHex) { int iLen = strHex.GetLength(); if (iLen > 2 || iLen < 1) { return 0; } else if (iLen == 1) { if (strHex == _T("A") || strHex == _T("a")) { return 10; } else if (strHex == _T("B") || strHex == _T("b")) { return 11; } else if (strHex == _T("C") || strHex == _T("c")) { return 12; } else if (strHex == _T("D") || strHex == _T("d")) { return 13; } else if (strHex == _T("E") || strHex == _T("e")) { return 14; } else if (strHex == _T("F") || strHex == _T("f")) { return 15; } else { return ::_ttoi(strHex); } } else { strHex.MakeReverse(); return HexToDec(strHex.Mid(1, 1)) * 16 + HexToDec(strHex.Mid(0, 1)); } }
TText8* CCommonUtils::DecToHex(const TDesC8& aHexDes) { TInt len = aHexDes.Length()/2; TText8* txt = new TText8[len+1]; for(TInt i=0; i<len; i++) { TPtrC8 ptr = aHexDes.Mid(i*2,2); TInt value; HexToDec(ptr,value); txt[i] = (TText8)value; } txt[len] = 0; return txt; }
std::string NumConverter::ToDecimal() { if (NumSys == dec) { return Val; } else { std::string s(""); if (NumSys == bin) { s = BinToDec(Val); } if (NumSys == oct) { s = OctToDec(Val); } if (NumSys == hex) { s = HexToDec(Val); } return s; } }
std::string NumConverter::ToBinary() { if (NumSys == bin) { return Val; } else { std::string s(""); if (NumSys == dec) { s = Val; s = DecToBin(s); } if (NumSys == oct) { s = OctToDec(Val); s = DecToBin(s); } if (NumSys == hex) { s = HexToDec(Val); s = DecToBin(s); } return s; } }
bool UseItemTable::SetTableData(void* pvTable, WCHAR* pwszSheetName, std::wstring* pstrDataName, BSTR bstrData) { if (0 == wcscmp(pwszSheetName, L"Table_Data_KOR")) { sUSE_ITEM_TBLDAT* pItem = (sUSE_ITEM_TBLDAT*)pvTable; if (0 == wcscmp(pstrDataName->c_str(), L"Tblidx")) { CheckNegativeInvalid(pstrDataName->c_str(), bstrData); pItem->tblidx = READ_DWORD(bstrData); } else if (0 == wcscmp(pstrDataName->c_str(), L"Use_Item_Active_Type")) { CheckNegativeInvalid(pstrDataName->c_str(), bstrData); pItem->byUse_Item_Active_Type = READ_BYTE(bstrData, pstrDataName->c_str()); } else if (0 == wcscmp(pstrDataName->c_str(), L"Buff_Group")) { pItem->byBuff_Group = READ_BYTE(bstrData, pstrDataName->c_str()); } else if (0 == wcscmp(pstrDataName->c_str(), L"Cool_Time_Bit_Flag")) { CheckNegativeInvalid(pstrDataName->c_str(), bstrData); pItem->dwCool_Time_Bit_Flag = HexToDec(bstrData); } else if (0 == wcscmp(pstrDataName->c_str(), L"Function_Bit_Flag")) { pItem->wFunction_Bit_Flag = (WORD)READ_BITFLAG(bstrData); } else if (0 == wcscmp(pstrDataName->c_str(), L"Appoint_Target")) { CheckNegativeInvalid(pstrDataName->c_str(), bstrData); pItem->byAppoint_Target = READ_BYTE(bstrData, pstrDataName->c_str()); } else if (0 == wcscmp(pstrDataName->c_str(), L"Apply_Target")) { CheckNegativeInvalid(pstrDataName->c_str(), bstrData); pItem->byApply_Target = READ_BYTE(bstrData, pstrDataName->c_str()); } else if (0 == wcscmp(pstrDataName->c_str(), L"Apply_Target_Max")) { CheckNegativeInvalid(pstrDataName->c_str(), bstrData); pItem->byApply_Target_Max = READ_BYTE(bstrData, pstrDataName->c_str()); } else if (0 == wcscmp(pstrDataName->c_str(), L"Apply_Range")) { CheckNegativeInvalid(pstrDataName->c_str(), bstrData); pItem->byApply_Range = READ_BYTE(bstrData, pstrDataName->c_str()); } else if (0 == wcscmp(pstrDataName->c_str(), L"Need_State_Bit_Flag")) { WORD wDummy = 0; pItem->wNeed_State_Bit_Flag = ~wDummy; pItem->wNeed_State_Bit_Flag = (WORD)READ_BITFLAG(bstrData, ~wDummy); } else if (0 == wcscmp(pstrDataName->c_str(), L"System_Effect_1")) { CheckNegativeInvalid(pstrDataName->c_str(), bstrData); pItem->aSystem_Effect[0] = READ_DWORD(bstrData); } else if (0 == wcscmp(pstrDataName->c_str(), L"System_Effect_Type_1")) { pItem->abySystem_Effect_Type[0] = READ_BYTE(bstrData, pstrDataName->c_str()); // [12/1/2006 zeroera] : 설명 : 테이블 체크로 옮길 것 //if (SYSTEM_EFFECT_APPLY_TYPE_FIRST > pItem->abySystem_Effect_Type[0] || // SYSTEM_EFFECT_APPLY_TYPE_LAST < pItem->abySystem_Effect_Type[0]) //{ // _ASSERT(0); // return false; //} } else if (0 == wcscmp(pstrDataName->c_str(), L"System_Effect_Value_1")) { pItem->afSystem_Effect_Value[0] = READ_FLOAT(bstrData, pstrDataName->c_str()); } else if (0 == wcscmp(pstrDataName->c_str(), L"System_Effect_2")) { pItem->aSystem_Effect[1] = READ_DWORD(bstrData); } else if (0 == wcscmp(pstrDataName->c_str(), L"System_Effect_Type_2")) { pItem->abySystem_Effect_Type[1] = READ_BYTE(bstrData, pstrDataName->c_str()); // [12/1/2006 zeroera] : 설명 : 테이블 체크로 옮길 것 //if (SYSTEM_EFFECT_APPLY_TYPE_FIRST > pItem->abySystem_Effect_Type[1] || // SYSTEM_EFFECT_APPLY_TYPE_LAST < pItem->abySystem_Effect_Type[1]) //{ // _ASSERT(0); // return false; //} } else if (0 == wcscmp(pstrDataName->c_str(), L"System_Effect_Value_2")) { pItem->afSystem_Effect_Value[1] = READ_FLOAT(bstrData, pstrDataName->c_str()); } else if (0 == wcscmp(pstrDataName->c_str(), L"Require_LP")) { pItem->wRequire_LP = READ_WORD(bstrData, pstrDataName->c_str(), 0); } else if (0 == wcscmp(pstrDataName->c_str(), L"Require_EP")) { pItem->wRequire_EP = READ_WORD(bstrData, pstrDataName->c_str(), 0); } else if (0 == wcscmp(pstrDataName->c_str(), L"Require_RP_Ball")) { pItem->byRequire_RP_Ball = READ_BYTE(bstrData, pstrDataName->c_str(), 0); } else if (0 == wcscmp(pstrDataName->c_str(), L"Casting_Time")) { pItem->fCasting_Time = READ_FLOAT(bstrData, pstrDataName->c_str(), 0.0f); pItem->dwCastingTimeInMilliSecs = (DWORD)(pItem->fCasting_Time * 1000.0f); } else if (0 == wcscmp(pstrDataName->c_str(), L"Cool_Time")) { pItem->wCool_Time = READ_WORD(bstrData, pstrDataName->c_str(), 0); pItem->dwCoolTimeInMilliSecs = pItem->wCool_Time * 1000; } else if (0 == wcscmp(pstrDataName->c_str(), L"Keep_Time")) { pItem->wKeep_Time = READ_WORD(bstrData, pstrDataName->c_str(), 0); pItem->dwKeepTimeInMilliSecs = pItem->wKeep_Time * 1000; } else if (0 == wcscmp(pstrDataName->c_str(), L"Keep_Effect")) { CheckNegativeInvalid(pstrDataName->c_str(), bstrData); pItem->bKeep_Effect = READ_BOOL(bstrData, pstrDataName->c_str()); } else if (0 == wcscmp(pstrDataName->c_str(), L"Use_Range_Min")) { pItem->byUse_Range_Min = READ_BYTE(bstrData, pstrDataName->c_str(), 0); pItem->fUse_Range_Min = (float)(pItem->byUse_Range_Min); } else if (0 == wcscmp(pstrDataName->c_str(), L"Use_Range_Max")) { pItem->byUse_Range_Max = READ_BYTE(bstrData, pstrDataName->c_str(), 0); pItem->fUse_Range_Max = (float)(pItem->byUse_Range_Max); } else if (0 == wcscmp(pstrDataName->c_str(), L"Use_Info_Text")) { pItem->Use_Info_Text = READ_DWORD(bstrData); } else if (0 == wcscmp(pstrDataName->c_str(), L"Casting_Effect")) { READ_STRING(bstrData, pItem->szCasting_Effect, _countof(pItem->szCasting_Effect)); } else if (0 == wcscmp(pstrDataName->c_str(), L"Action_Effect")) { READ_STRING(bstrData, pItem->szAction_Effect, _countof(pItem->szAction_Effect)); } else if (0 == wcscmp(pstrDataName->c_str(), L"Casting_Animation_Start")) { pItem->wCasting_Animation_Start = READ_WORD(bstrData, pstrDataName->c_str()); } else if (0 == wcscmp(pstrDataName->c_str(), L"Casting_Animation_Loop")) { pItem->wCasting_Animation_Loop = READ_WORD(bstrData, pstrDataName->c_str()); } else if (0 == wcscmp(pstrDataName->c_str(), L"Action_Animation_Index")) { pItem->wAction_Animation_Index = READ_WORD(bstrData, pstrDataName->c_str()); } else if (0 == wcscmp(pstrDataName->c_str(), L"Action_Loop_Animation_Index")) { pItem->wAction_Loop_Animation_Index = READ_WORD(bstrData, pstrDataName->c_str()); } else if (0 == wcscmp(pstrDataName->c_str(), L"Action_End_Animation_Index")) { pItem->wAction_End_Animation_Index = READ_WORD(bstrData, pstrDataName->c_str()); } else if (0 == wcscmp(pstrDataName->c_str(), L"Casting_Effect_Position")) { pItem->byCastingEffectPosition = READ_BYTE(bstrData, pstrDataName->c_str()); } else if (0 == wcscmp(pstrDataName->c_str(), L"Action_Effect_Position")) { pItem->byActionEffectPosition = READ_BYTE(bstrData, pstrDataName->c_str()); } else if (0 == wcscmp(pstrDataName->c_str(), L"UseLoc_X")) { pItem->fUseLoc_X = READ_FLOAT(bstrData, pstrDataName->c_str()); } else if (0 == wcscmp(pstrDataName->c_str(), L"UseLoc_Z")) { pItem->fUseLoc_Z = READ_FLOAT(bstrData, pstrDataName->c_str()); } else if (0 == wcscmp(pstrDataName->c_str(), L"UseLoc_Radius")) { pItem->fUseLoc_Radius = READ_FLOAT(bstrData, pstrDataName->c_str()); } else if (0 == wcscmp(pstrDataName->c_str(), L"RequiredQuestID")) { pItem->RequiredQuestID = (QUESTID)(READ_WORD(bstrData, pstrDataName->c_str())); } else { Table::CallErrorCallbackFunction(L"[File] : %s\n[Error] : Unknown field name found!(Field Name = %s)", m_wszXmlFileName, pstrDataName->c_str()); return false; } } else { return false; } return true; }
int main(void) { int t=0; t = HexToDec("a821"); return 0; }