PDA

View Full Version : C++, Learning the basics, have question about constants.


demoneyejin
11-03-2009, 07:01 PM
I'm currently learning from an online resource how to code in C++.

the website is http://www.cplusplus.com/doc/tutorial/constants/

and as you can tell from that link, I've come up to constants but I don't feel like I've completely grasped the concept of it. :(

They have a portion in which they explain octal (base 8) and hexadecimal (base 16) and that's where I lose grasp. Anyone able to explain this in simpler terms or break it down so that I understand how they got the octal of 75 to 0113? same for the hexadecimal ?

oesxyl
11-03-2009, 07:27 PM
I'm currently learning from an online resource how to code in C++.

the website is http://www.cplusplus.com/doc/tutorial/constants/

and as you can tell from that link, I've come up to constants but I don't feel like I've completely grasped the concept of it. :(

They have a portion in which they explain octal (base 8) and hexadecimal (base 16) and that's where I lose grasp. Anyone able to explain this in simpler terms or break it down so that I understand how they got the octal of 75 to 0113? same for the hexadecimal ?
do you mean the conversion from one base to others?

conversion from decimal to base 2:
75 = 37 * 2 + 1
37 = 18 * 2 + 1
18 = 9 * 2 + 0
9 = 4 * 2 + 1
4 = 2 * 2 + 0
2 = 1 * 2 + 0
1 = 0 * 2 + 1

that means, read from bottom to top 75 is 1001011 in base 2
split the value from right to left, 3 digits each piece -> 1 001 011, that means 113 in octal.
same way to get hexa but with 4 digits 100 1011, means 4b because:
1010 -> a
1011 -> b
1100 -> c
1101 -> d
1110 -> e
1111 -> f

I hope is simple enougt, :)

best regards