Question: Is there a simple way to convert a string of numbers separated by spaces into a vector of ints or something that I can easily convert into a vector? 

I am creating an input operator (>>) to make a binary tree using values input from command line. And this is the main that goes with it

```
int main(int argc, char **argv)
{
stringstream stream;
stream << " 10" << " 11" << " 10" << " 2" << endl;
tree = new binary_tree();
stream >> *tree;
if (tree->inorder() != string("7 10 11")) //inorder() prints the tree in order
cout << "Test passed" << endl;
delete tree;

return 0;
}

```

The problem I am having is that while I can create and print the values that I need, I can't convert them and put them into a vector - for which I have a working defined method that creates a tree from the values.

```
std::istream& operator>>(std::istream &in, binary_tree &value)
{
vector<int> input_tree;
string readline;     
getline(in, readline);
cout << "(" << readline << ")" << endl; //prints correctly - (10 11 10 2)

    //where I need to insert insert values into vector

for(int i = 0; i < input_tree.size(); i++)
{
    insert(input_tree[i], value);    //inserts the values from a vector into a binary tree
}

return in;  
} 

```

I have tried looping through the string and using stoi() on each character but it always errored whenever the spaces were causing errors.

Thanks for any help and sorry if I've missed any important information out.

Answer: 
The warning is because there is arithmetic conversions happening in the expression `uint16_t result = (x & (1 << 4) - 1) | (y);`. Here `(1<<4)-1` will have type int, and x is of type `unsigned char`, according to the rules of conversion, the result will be of type `int`, which does not fit into a `uint16_t` on your platform.

Reference, c11 std 6.3.1.8 on Usual arithmetic conversions:

> 
> Otherwise, if the type of the operand with signed integer type can represent
>  all of the values of the type of the operand with unsigned integer type, then
>  the operand with unsigned integer type is converted to the type of the
>  operand with signed integer type.
> 
> 
> 

To get the 4 lower bit of `x`, use `x & 0xF`. Also cast it to `uint16_t` before applying the shift operation,

```
uint16_t result = (uint16_t)(((x & 0xF) << 8) | y);

```

This will put the lower 4 bit of x ahead of y. The expression you used will or lower 4 bits of x with y, it does not do what you want.
> 
> Thats what Im wanting to do, just take the last 4 bits of y and put it with all of x. Making a 12 bit result 
> 
> 
> 

```
x = 01234567
y = 23458901
doBitWise = 890101234567

```

In that case, you should left shift the **y** by 8, and mask the front 4 bits:

```
uint16_t result = (((unsigned short)y << 8) & 0xF00) | x; //result will be casted to uint16_t

```

Note: be careful of the operator precedence. + comes before <<, thus parentheses is needed

Note 2: to prevent undefined behavior when int is 16-bit and to ensure that the result of y << 8 will be having at least 16-bit, explicit casting to unsigned short is added (since y is originally unsigned char). Besides, the inserting of x is using bitwise OR operator |.