Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/142.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 从二进制字符串中一次提取16位,求和并更新数组?_C++_Arrays_Binary_Sum - Fatal编程技术网

C++ 从二进制字符串中一次提取16位,求和并更新数组?

C++ 从二进制字符串中一次提取16位,求和并更新数组?,c++,arrays,binary,sum,C++,Arrays,Binary,Sum,我有以下几点:我曾想过使用位集,但不知道这是否是一种非常可行的方法。我如何将其应用于m[top]。因为m[top]本身是一个8位整数数组索引,所以我在索引它时遇到了问题。我不知道如何将这个m[top]保存到另一个无限长的数组中。我的字符串是可变的…我无法设置数组大小来保存它,或者我可以吗?m[top]是8位整数数组吗?你的帖子说它是一个二进制字符串,它传达了一种想法,即它是一个由“0”和“1”组成的字符序列。你应该编辑它。这个阵法有多长?@Filipe:iv纠正了它。你说得对。附加8个零填充位的

我有以下几点:我曾想过使用位集,但不知道这是否是一种非常可行的方法。我如何将其应用于m[top]。因为m[top]本身是一个8位整数数组索引,所以我在索引它时遇到了问题。我不知道如何将这个m[top]保存到另一个无限长的数组中。我的字符串是可变的…我无法设置数组大小来保存它,或者我可以吗?
m[top]
是8位整数数组吗?你的帖子说它是一个二进制字符串,它传达了一种想法,即它是一个由“0”和“1”组成的字符序列。你应该编辑它。这个阵法有多长?@Filipe:iv纠正了它。你说得对。附加8个零填充位的8位字符串。但是我想一次选16位,也就是2米[top],有人能帮我吗,我好像想不出来。
#include <iostream>
using namespace std;

int main()
{
    char character;
    int i;
    int m[8];


    cout<<"Please enter a character string: ";
    cin>>character;
    cout<<"You've entered "<<character<<endl; 
    //i entered abcd it gives me 01100001011000100110001101100100 in cout. how should i save this         
    as a continuous array? 
    for(i=0;i<8;i++)
    {
        m[i]=character%2;
        character = character/2;
    }

    int top, bottom;

    for(bottom=0,top =7; bottom<8; bottom++,top--)
    {
        m[bottom]=m[top];
        cout<<m[top];
    }

    return 0;
     }