For my SIC assembler written in C++ , I need a hexadecimal integer as the location counter. That is if LOCCTR=A and LOCCTR++ should store B in LOCCTR. Is there such an variable in C++? If so how do I make it Hexadecimal?? I know how to Initialize an int variable with Hex value , int var=0x0
But my question will it remain a hexadecimal integer after increment operation? If not, how to convert it to hex

## Recommended Answers

What you need to remember is that both decimal and hexadecimal are only representations of the integer value, which is actually a binary value. Thus, it is only when you go to display the value that it becomes either decimal or hexadecimal, and the same value can be displayed either …

## All 3 Replies

What you need to remember is that both decimal and hexadecimal are only representations of the integer value, which is actually a binary value. Thus, it is only when you go to display the value that it becomes either decimal or hexadecimal, and the same value can be displayed either way.

To write a hex value an output stream, you will want to use the `hex` manipulator, which sets the output format for the following numeric fields. For example:

``cout << hex << myInteger;``

printf("%04X\t%s\t%s\t%s%\n",temp.lc,temp.label,temp.opcode,temp.operand);

I want a turbo C++ cout equivalent for this statement! Somebody please help!!

Now, now, there's no need to shout.

I gather that the manipulator I'd recommended earlier didn't work? Or is this a further question about how to get the appropriate field spacing? Ordinarily, I'd say use

``````cout << setw(4)  << setfill('0') << hex << temp.lc
<< setw(4)  << setfill(' ') << " "
<< setw(16) << temp.label
<< setw(8)  << temp.opcode
<< setw(8)  << temp.operand
<< endl;``````

... but I'm not certain if it would work under such an old compiler. Also, it is not exactly the same as your original statement (it uses field widths instead of tabs), but it should work out to the same output in almost all cases.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.