int main() { long numberToConvert; int baseToConvert; cout<<"This Program will convert any number of any base (<10) to its decimal equivalent"<<endl; cout<<"Enter number: "; cin>>numberToConvert; //Reading the number to be converted cout<<"Enter Base (between 2 and 10): "; cin>>baseToConvert; //reading the base of the number to be converted Convert convertNumber; if(convertNumber.checkValidity(numberToConvert,baseToConvert))/// check if the number-base is valid { cout<<"Decimal number equivalent is:"<<convertNumber.convertToDecimal()<<endl; // print the decimal equivalent } //end if else { cout<<"Invalid number or/and base entered"<<endl; } //end else return 0; } // end main
vector<unsigned short> IceUtilInternal::toUTF16(const vector<Byte>& source) { vector<unsigned short> result; if(!source.empty()) { #ifdef ICE_HAS_CODECVT_UTF8 assert(sizeof(Char16T) == sizeof(unsigned short)); typedef wstring_convert<codecvt_utf8_utf16<Char16T>, Char16T> Convert; Convert convert; try { Convert::wide_string ws = convert.from_bytes(reinterpret_cast<const char*>(&source.front()), reinterpret_cast<const char*>(&source.front() + source.size())); result = vector<unsigned short>(reinterpret_cast<const unsigned short*>(ws.data()), reinterpret_cast<const unsigned short*>(ws.data()) + ws.length()); } catch(const std::range_error& ex) { throw IllegalConversionException(__FILE__, __LINE__, ex.what()); } #else convertUTF8ToUTF16(source, result); #endif } return result; }
vector<Byte> IceUtilInternal::fromUTF32(const vector<unsigned int>& source) { vector<Byte> result; if(!source.empty()) { #ifdef ICE_HAS_CODECVT_UTF8 assert(sizeof(Char32T) == sizeof(unsigned int)); typedef wstring_convert<codecvt_utf8<Char32T>, Char32T> Convert; Convert convert; try { Convert::byte_string bs = convert.to_bytes(reinterpret_cast<const Char32T*>(&source.front()), reinterpret_cast<const Char32T*>(&source.front() + source.size())); result = vector<Byte>(reinterpret_cast<const Byte*>(bs.data()), reinterpret_cast<const Byte*>(bs.data()) + bs.length()); } catch(const std::range_error& ex) { throw IllegalConversionException(__FILE__, __LINE__, ex.what()); } #else convertUTF32ToUTF8(source, result); #endif } return result; }
void Enemy::Initialize(b2World& world, b2Vec2 position) { bodyDef.position = position; bodyDef.type = b2_dynamicBody; bodyDef.fixedRotation = true; body = world.CreateBody(&bodyDef); Convert convert; b2Vec2 vs0, vs1, vs2, vs3; b2Vec2* vs = new b2Vec2[4]; vs0 = convert.CoordPixelsToWorld(0, 50, 50.0f, 50.0f); vs1 = convert.CoordPixelsToWorld(0, 0, 50.0f, 50.0f); vs2 = convert.CoordPixelsToWorld(50, 0, 50.0f, 50.0f); vs3 = convert.CoordPixelsToWorld(50, 50, 50.0f, 50.0f); vs[0].Set(vs0.x, vs0.y); vs[1].Set(vs1.x, vs1.y); vs[2].Set(vs2.x, vs2.y); vs[3].Set(vs3.x, vs3.y); shape.Set(vs, 4); delete vs; fixtureDef.density = 1.0f; fixtureDef.friction = 0.0f; fixtureDef.shape = &shape; body->CreateFixture(&fixtureDef); b2Fixture* enemySensorFixture = body->CreateFixture(&fixtureDef); ContactUserData* cud = new ContactUserData(); cud->type = ContactUserData::Type::ENEMY; cud->data = this; enemySensorFixture->SetUserData(cud); }
QString TransitionInfoBin::getOutputsStrASCII() { unsigned char ascii[MAX_CHARARRAY_LENGTH]; int len; Convert conv; outputs->convertToASCII(ascii, MAX_CHARARRAY_LENGTH, len, FALSE); return conv.asciiToReadableStr(ascii, len); }
static bool match(UnsafeRawOp* x, Instruction** base, Instruction** index, int* log2_scale) { Instruction* instr_to_unpin = NULL; ArithmeticOp* root = x->base()->as_ArithmeticOp(); if (root == NULL) return false; // Limit ourselves to addition for now if (root->op() != Bytecodes::_ladd) return false; // Try to find shift or scale op if (match_index_and_scale(root->y(), index, log2_scale, &instr_to_unpin)) { *base = root->x(); } else if (match_index_and_scale(root->x(), index, log2_scale, &instr_to_unpin)) { *base = root->y(); } else if (root->y()->as_Convert() != NULL) { Convert* convert = root->y()->as_Convert(); if (convert->op() == Bytecodes::_i2l && convert->value()->type() == intType) { // pick base and index, setting scale at 1 *base = root->x(); *index = convert->value(); *log2_scale = 0; } else { return false; } } else { // doesn't match any expected sequences return false; } // Typically the addition is pinned, as it is the result of an // inlined routine. We want to unpin it so as to avoid the long // addition, but in order to do so we must still ensure that the // operands are pinned, as they may be computed arbitrarily before // the Unsafe op completes (even if the Unsafe op is pinned). At // this point we do not really need to pin Unsafe raw or object // gets. if (root->is_pinned()) { if (root->pin_state() == Instruction::PinInlineReturnValue) { assert(x->is_pinned(), "All unsafe raw ops should be pinned"); root->unpin(Instruction::PinInlineReturnValue); (*base)->pin(); (*index)->pin(); } else { // can't safely unpin this instruction return false; } } if (PrintUnsafeOptimization && instr_to_unpin != NULL) { tty->print_cr("pin_state = 0x%x", instr_to_unpin->pin_state()); instr_to_unpin->print(); } return true; }
//编码问题,如果是gbk,则转成utf8 string Doc::charset_convert() { string pattern = "charset\\s?=\\s?(.*?)\""; Regex *regex = new Regex(pattern); string charset = regex->match_one(content, 1); if (charset == "utf-8" || charset == "utf8") //如果文档是utf8编码,则不做特别处理 return content; else if (charset == "gbk" || charset == "gb2312") //如果是gbk编码,则转换成utf8编码 { Convert *con = new Convert("gbk", "utf8"); return con->exec(content); } else //其他编码不予以考虑,直接跳过 return ""; }
void Information_Hiding::Execute(ifstream &CoverData, ofstream &StegoData){ Convert convert; int in = 0; int index = 0; int counter = 0; char CharOfMessBinary[8] = {'\0'}; while(CoverData.good()) { bool isChange = false; char CharOfImageBinary[8] = {'\0'}; char c = CoverData.get(); int ascii = (int)c; int _ascii = abs(ascii); if(ascii != _ascii) isChange = true; convert.ConvertToBinary(_ascii, CharOfImageBinary); if(counter >= 55){ bool flag = false; //-----------------------------------------------------// if(index == 0 && in < message.length()-1){ char encodeChar = message[in]; int asc = (int)encodeChar; convert.ConvertToBinary(asc, CharOfMessBinary); flag = true; } if(in >= message.length() -1 ){ index = -1; } //------------------------------------------------------// if(index != -1){ CharOfImageBinary[7] = CharOfMessBinary[index]; StegoData << convert.ConvertToChar(CharOfImageBinary,isChange); } else StegoData << c; if(index != -1){ index++; if(index == 8){ index = 0; in++; } } } if(counter < 55) StegoData << c; counter++; } }
int main(int argc, char const* argv[]) { google::InitGoogleLogging(argv[0]); FLAGS_logtostderr = true; ilInit(); LOG(INFO) << "Using devil library version " << ilGetInteger(IL_VERSION_NUM); // Allocate images ILuint images[2]; // 0 for read, 1 for write ilGenImages(2, images); IL_CHECK_ERROR(); // Read image ilBindImage(images[0]); ilLoadImage("lena_color.bmp"); IL_CHECK_ERROR(); auto bpp = ilGetInteger(IL_IMAGE_BPP); // bpp = byte per pixels CHECK_EQ(bpp, 3) << "BPP must be 3"; auto w = ilGetInteger(IL_IMAGE_WIDTH); auto h = ilGetInteger(IL_IMAGE_HEIGHT); LOG(INFO) << "Load image width = " << w << ", height = " << h; ILubyte *color_img_ptr = ilGetData(); IL_CHECK_ERROR(); // Allocate image for store ilBindImage(images[1]); IL_CHECK_ERROR(); ilTexImage(w, h, 1, bpp, IL_LUMINANCE, IL_UNSIGNED_BYTE, NULL); ILubyte *gray_img_ptr = ilGetData(); IL_CHECK_ERROR(); // Convert! Convert c; c.RGB2Gray(color_img_ptr, gray_img_ptr, w, h); // store image ilBindImage(images[1]); ilEnable(IL_FILE_OVERWRITE); ilSaveImage("lena_gray.bmp"); IL_CHECK_ERROR(); ilDeleteImages(2, images); return 0; }
PosibErr<char *> operator() (char * str, size_t sz) { if (conv) { buf.clear(); RET_ON_ERR(conv->convert_ec(str, sz, buf, buf0, str)); return buf.mstr(); } else { return str; } }
const char * operator() (const char * str, size_t sz) { if (conv) { buf.clear(); conv->convert(str, sz, buf, buf0); return buf.str(); } else { return str; } }
const char * operator() (ParmStr str) { if (conv) { buf.clear(); conv->convert(str, -1, buf, buf0); return buf.mstr(); } else { return str; } }
PosibErr<const char *> operator() (ParmStr str) { if (conv) { buf.clear(); RET_ON_ERR(conv->convert_ec(str, -1, buf, buf0, str)); return buf.mstr(); } else { return str.str(); } }
int main (int argc, char* argv[]) { if (argc != 4) { error("usage: %s number base1 base2", argv[0]); return 1; } std::string str(argv[1]); int base1 = std::stoi(std::string(argv[2])); int base2 = std::stoi(std::string(argv[3])); Convert convert; try { std::string res; res = convert.convert(str, base1, base2); std::cout << str << " in base " << base2 << " is " << res << std::endl; } catch(const std::invalid_argument& ia) { error("%s", ia.what()); return 1; } return 0; }
/** * Returns a string representing the coding of the state * * @param type If 'Binary' a binary string is returned, otherwise an integer string. * @returns The resulting string */ QString State::getCodeStr(int type/*=-1*/) { Convert conv; QString res; int stateCodeSize; stateCodeSize=machine->getNumEncodingBits(); if (type==-1) type = machine->getType(); switch (type) { case Binary: res = conv.intToBinStr(code, stateCodeSize); return res; default: res.setNum(code); return res; } }
char * operator() (char c) { buf.clear(); if (conv) { char str[2] = {c, 0}; conv->convert(str, 1, buf, buf0); } else { buf.append(c); } return buf.mstr(); }
void ParserManager::ShowConvertingInfo() { HWND conv_tab = GetPrgRes()->GetTabWindow(TabWindowFunctions::tab_convert); if( conv_type==0 || conv_input_unit==-1 || conv_output_unit==-1 || conv_input_unit == conv_output_unit ) { SetDlgItemText(conv_tab, IDC_EDIT_OUTPUT_INFO, ""); return; } Convert * pconv = GetPrgRes()->GetConvert(); // the first unit to the second ttmath::Big<1,1> result; result.SetOne(); std::string buffer1 = "1 "; buffer1 += pconv->GetUnitAbbr(country, conv_input_unit); buffer1 += " = "; if( pconv->Conversion(conv_input_unit, conv_output_unit, result) ) { SetDlgItemText(conv_tab, IDC_EDIT_OUTPUT_INFO, "overflow" ); return; } result.ToString(buffer2, 10, false, 3, -1, true); buffer1 += buffer2; buffer1 += " "; buffer1 += pconv->GetUnitAbbr(country, conv_output_unit); // the second unit to the first buffer1 += " 1 "; buffer1 += pconv->GetUnitAbbr(country, conv_output_unit); buffer1 += " = "; result.SetOne(); if( pconv->Conversion(conv_output_unit, conv_input_unit, result) ) { SetDlgItemText(conv_tab, IDC_EDIT_OUTPUT_INFO, "overflow" ); return; } result.ToString(buffer2, 10, false, 3, -1, true); buffer1 += buffer2; buffer1 += " "; buffer1 += pconv->GetUnitAbbr(country, conv_input_unit); SetDlgItemText(conv_tab, IDC_EDIT_OUTPUT_INFO, buffer1.c_str() ); }
void Canonicalizer::do_StoreField (StoreField* x) { // If a value is going to be stored into a field or array some of // the conversions emitted by javac are unneeded because the fields // are packed to their natural size. Convert* conv = x->value()->as_Convert(); if (conv) { Value value = NULL; BasicType type = x->field()->type()->basic_type(); switch (conv->op()) { case Bytecodes::_i2b: if (type == T_BYTE) value = conv->value(); break; case Bytecodes::_i2s: if (type == T_SHORT || type == T_BYTE) value = conv->value(); break; case Bytecodes::_i2c: if (type == T_CHAR || type == T_BYTE) value = conv->value(); break; } // limit this optimization to current block if (value != NULL && in_current_block(conv)) { set_canonical(new StoreField(x->obj(), x->offset(), x->field(), value, x->is_static(), x->state_before(), x->needs_patching())); return; } } }
int main() { int number, base, answer; //RECEIVE INPUT cout << "Please enter an integer: "; cin >> number; cout << "Please enter the base of that integer: "; cin >> base; //CALL CONVERT Convert c; //create convert obj answer = c.convertToDec(number, base); //GIVE ANSWER if (answer != -1) cout << "The given integer in decimal format is: " << answer << "." << endl; else cout << "The given integer " << number << " with base " << base << " is invalid." << endl; return 0; }
/** * Proceeds with the next step in the simulation. * Reads the inputs from the inputs field and sends them to the machine. */ void Simulator::next() { QString in, out; int numin, numout; GState* next_state; Convert conv; IOInfo* ioinfo; IOInfoBin iobin(IO_MealyIn); IOInfoASCII ioascii(IO_MealyIn); Error err; numin = machine->getNumInputs(); numout = machine->getNumOutputs(); in = simdlg->getInputs(); // bin = new char[numin+1]; if (simdlg->isIBinChecked()) { if (Transition::conditionValid(Binary, in, FALSE)) { if (!simdlg->isClockOn()) err.info(tr("Input is not in binary format.")); else //simdlg->setInputs(""); simdlg->clearInput(); return; } iobin = conv.binStrToX10(numin, in, IO_MealyIn); ioinfo = &iobin; } else if (simdlg->isIHexChecked()) { QString intmp=in; intmp = intmp.replace(QRegExp("[0-9a-fA-F\\s]"), ""); if (!intmp.isEmpty()) { if (!simdlg->isClockOn()) err.info(tr("Input is not in hexadecimal format.")); else //simdlg->setInputs(""); simdlg->clearInput(); return; } iobin = conv.hexStrToX10(numin, in, IO_MealyIn); ioinfo = &iobin; } else // ASCII { ioascii.setInfo(in); ioinfo = &ioascii; if (!ioascii.isSingle()) { if (!ioascii.getInfo().isEmpty() && !simdlg->isClockOn()) err.info(tr("The input is not a single character.")); // else //simdlg->setInputs(""); simdlg->clearInput(); return; } } // IOInfoBin ioinfo(bin, numin); next_state = next(ioinfo, out); if (next_state) { simdlg->setOutputs(out); setCurrentState(next_state); main->repaintViewport(); } if (simdlg->isClockOn() && simdlg->isIASCIIChecked()) { simdlg->resetBits(); simdlg->clearInput(); } else simdlg->selectFirst(); // delete [] bin; }
// Here we set all the flags void ScanBlocks::scan_block(BlockBegin* block, ScanResult* desc, bool live_only) { for (Instruction* n = block; n != NULL; n = n->next()) { if (live_only && !n->is_pinned() && (n->use_count() == 0)) { // don't look at unused instructions because no code is emitted for them continue; } ValueTag tag = n->type()->tag(); if (tag == floatTag) desc->set_has_floats(true); else if (tag == doubleTag) desc->set_has_doubles(true); if (n->as_StateSplit() != NULL) { if (n->as_Invoke() != NULL) { desc->set_has_calls(true); } else if (n->as_NewArray() || n->as_NewInstance() || n->as_AccessMonitor()) { desc->set_has_slow_cases(true); } else if(n->as_Intrinsic() != NULL) { Intrinsic* i = n->as_Intrinsic(); if (i->id() == methodOopDesc::_arraycopy) desc->set_has_slow_cases(true); if (!i->preserves_state()) desc->set_has_calls(true); } } else if (n->as_AccessField() != NULL) { AccessField* af = n->as_AccessField(); if (!af->is_initialized() || !af->is_loaded()) desc->set_has_class_init(true); } else if (n->as_AccessLocal() != NULL) { AccessLocal* local = n->as_AccessLocal(); StoreLocal* store = n->as_StoreLocal(); int use_count = 0; if (store != NULL) { if (!store->is_eliminated()) { use_count = 1; } } else { use_count = n->use_count(); } if (use_count > 0) { ValueType* type = local->type(); assert(local->has_offset(), "must have had offset allocated"); accumulate_access(in_words(local->offset()), tag, use_count); } } #ifdef SPARC else { if (n->as_Convert() != NULL) { Convert* conv = n->as_Convert(); switch (conv->op()) { case Bytecodes::_l2f: case Bytecodes::_l2d: case Bytecodes::_f2l: case Bytecodes::_d2l: case Bytecodes::_d2i: { desc->set_has_calls(true); break; } } } else if (n->as_ArithmeticOp() != NULL) { ArithmeticOp* arith = n->as_ArithmeticOp(); switch (arith->op()) { case Bytecodes::_lrem: case Bytecodes::_ldiv: case Bytecodes::_lmul: case Bytecodes::_drem: case Bytecodes::_frem: { desc->set_has_calls(true); break; } } } } #endif } }
static bool match_index_and_scale(Instruction* instr, Instruction** index, int* log2_scale, Instruction** instr_to_unpin) { *instr_to_unpin = NULL; // Skip conversion ops Convert* convert = instr->as_Convert(); if (convert != NULL) { instr = convert->value(); } ShiftOp* shift = instr->as_ShiftOp(); if (shift != NULL) { if (shift->is_pinned()) { *instr_to_unpin = shift; } // Constant shift value? Constant* con = shift->y()->as_Constant(); if (con == NULL) return false; // Well-known type and value? IntConstant* val = con->type()->as_IntConstant(); if (val == NULL) return false; if (shift->x()->type() != intType) return false; *index = shift->x(); int tmp_scale = val->value(); if (tmp_scale >= 0 && tmp_scale < 4) { *log2_scale = tmp_scale; return true; } else { return false; } } ArithmeticOp* arith = instr->as_ArithmeticOp(); if (arith != NULL) { if (arith->is_pinned()) { *instr_to_unpin = arith; } // Check for integer multiply if (arith->op() == Bytecodes::_imul) { // See if either arg is a known constant Constant* con = arith->x()->as_Constant(); if (con != NULL) { *index = arith->y(); } else { con = arith->y()->as_Constant(); if (con == NULL) return false; *index = arith->x(); } if ((*index)->type() != intType) return false; // Well-known type and value? IntConstant* val = con->type()->as_IntConstant(); if (val == NULL) return false; switch (val->value()) { case 1: *log2_scale = 0; return true; case 2: *log2_scale = 1; return true; case 4: *log2_scale = 2; return true; case 8: *log2_scale = 3; return true; default: return false; } } } // Unknown instruction sequence; don't touch it return false; }