What are octal integer constants and hexadecimal integer constants? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What are octal integer constants and hexadecimal integer constants?

Also rules to write them

22nd Aug 2018, 7:31 AM
Sandy
5 Answers
+ 7
if you want algorithm to convert integers to octal then it would be like this : while(num > 0) { cout << num % 8; num /= 8; } for integers to hex int num = 235458; vector<char> myVec; while(num > 0) { int hex = num % 16; if(hex > 9) myVec.push_back((char)(hex - 10 + 'A')); else myVec.push_back((char)(hex + 48)); num /= 16; } for(int i = myVec.size() - 1; i >= 0; i--) cout << myVec.at(i);
22nd Aug 2018, 10:21 AM
blACk sh4d0w
blACk sh4d0w - avatar
+ 1
I was hesitated to see that you wrote octal & hexadecimal integer constants, are you asking how to create a constant in octal & hexadecimal, or how to write an integer in a certain base (octal & hexadecimal)? Also you need to specify which language in question tags.
22nd Aug 2018, 7:43 AM
Ipang
0
please explain rule to write them as such
22nd Aug 2018, 7:42 AM
Sandy
0
im asking in c++. iwant t know how to write random integers like 13 in their format
22nd Aug 2018, 8:24 AM
Sandy
0
please tel the algorithm to get it
22nd Aug 2018, 8:49 AM
Sandy