Здравствуйте!
Нужна прога на С++
В общем нужен калькулятор с возможностью считать в различных системах счисления.
Ответы
Ответ дал:
0
//Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23506 for x64
#include <iostream>
#include <bitset>
#include <sstream>
const size_t hex(const std::string& number)
{
size_t u_num = 0U;
std::istringstream ost(number);
ost >> std::hex >> u_num;
return u_num;
}
template <typename L, typename R>
const size_t& calculate(const L& l, const R& r)
{
return std::bitset<16>(l).to_ulong() + std::bitset<16>(r).to_ulong();
}
int main()
{
std::cout << calculate(hex("7c"), 5) << std::endl;
std::cout << calculate("11", hex("1d")) << std::endl;
}
#include <iostream>
#include <bitset>
#include <sstream>
const size_t hex(const std::string& number)
{
size_t u_num = 0U;
std::istringstream ost(number);
ost >> std::hex >> u_num;
return u_num;
}
template <typename L, typename R>
const size_t& calculate(const L& l, const R& r)
{
return std::bitset<16>(l).to_ulong() + std::bitset<16>(r).to_ulong();
}
int main()
{
std::cout << calculate(hex("7c"), 5) << std::endl;
std::cout << calculate("11", hex("1d")) << std::endl;
}
Похожие вопросы
2 года назад
2 года назад
8 лет назад
9 лет назад