将50位二进制值转换为整数

时间:2016-10-16 02:00:53

标签: c++ string long-integer type-conversion

我在c ++中有一个50位的字符串(在外部txt文件中)为1s和0s,需要在systemC中使用它(这里不关心)。 现在的问题是: 首先需要将50位字符串转换为整数,然后将整数转换为字符串以达到我的目的。 但是当我将字符串转换为整数时,它并不像预期的那样反映结果。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js">
</script>
<style></style>
<div id="transition-wrapper">
  <div id="transition">
  </div>
</div>

2 个答案:

答案 0 :(得分:2)

这里的朋友是strtoll

即。变化

value = atoi(a.c_str());

long long int value = strtoll(a.c_str(), NULL, 2);

答案 1 :(得分:0)

从C ++ 11开始,我们有std::sto*个函数:

long long value = std::stoll(a, nullptr, 2);
相关问题