# Hex

• 06-22-2005
ILoveVectors
Hex
Suppose i wanted to store a sieres of hexadecmial
numbers in a vector.

would i need to define it vector<int> ?
• 06-22-2005
Charmy
Depends if you want their corrosponding value or if you want to keep the actual 0x2F format.

for example.

Code:

```int main() {         vector<int> hexs;//or Long if your doing big hex 0x3423F3         hexs.push_back(0x12);         cout<<hexs[0]<<endl;         getch(); }```
Will produce 18 as output, since its the corrosponding decimal Value.

If you want to keep the 0x12 format you could just do them as strings.

Code:

```int main() {         vector<char *> hexs;         hexs.push_back("0x12");         cout<<hexs[0]<<endl;         getch(); }```
But clearly this doesn't allow you to get the actual hex value =P so it probably isn't what you want. but maybe it is..

If your looking for a way to add hex values... hmm you could use strings but you would have to write the calculator yourself where you would just parse the hex values and then do the math based on the characters that you pull out. <shrug>

But afaik there are no built in types with C++ that store the hex value in its actual hex form.
• 06-22-2005
hk_mp5kpdw
Yes, use a vector<int> container. If you need to do any output and have the results come up as hex, just use the hex stream manipulator.

Taking Charmy's example and tweaking it a bit:
Code:

```#include <iostream> #include <iomanip> #include <vector> using namespace std; int main() {     vector<int> hexs;     hexs.push_back(0x12);     cout << hex << showbase << hexs[0] << endl;     cin.get();     return 0; }```
Should output:
Code:

`0x12`
• 06-22-2005
Charmy
Hey cool, i learned somthing new today =). didn't know showbase did that. Very cool... Does that mean if you add to values together it will return the correct hex value?
• 06-22-2005
ILoveVectors
```#include <iostream> using namespace std; int main() {         int num = 2;         cout<<num<<endl;         cout<<hex<<showbase<<num<<endl;         cout<<oct<<showbase<<num<<endl<<endl;         int another_num = 24;         cout<<dec<<another_num<<endl;         cout<<hex<<showbase<<another_num<<endl;         cout<<oct<<showbase<<another_num<<endl<<endl;         int sum = num + another_num;                 cout<<dec<<sum<<endl;         cout<<hex<<showbase<<sum<<endl;         cout<<oct<<showbase<<sum<<endl;         return 0; }```