0

Why does this code not show this number?

#include<iostream> using namespace std; int main () { int myPhone = 2^12; cout << myPhone; return 0; }

28th Feb 2019, 9:54 AM
Thokgamo Shadreck
Thokgamo Shadreck - avatar
12 Respostas
+ 9
Thokgamo Shadreck which number you wrote is belong to some other user and it can be misuse so I edited with that so please be careful in typing phone number ranges.
28th Feb 2019, 11:57 AM
GAWEN STEASY
GAWEN STEASY - avatar
+ 5
What exactly do you want to do? 2 ^ 12 yields 14, but in case you meant to raise 2 by 14 `pow(2, 14)` then you'll get 4096. Both these numbers are within the safe range of `int`. I think the problem isn't because it was out of range value. Can you explain further of your intention?
28th Feb 2019, 11:20 AM
Ipang
+ 4
Maximum value you can assign to a integer in c++ is 2147483647. The phone number exceeds the limitation. As you are not going to do mathematical operations for phone number, it's better to define it a String.
28th Feb 2019, 10:13 AM
Parsa Gholipout
Parsa Gholipout - avatar
+ 2
Alright, a minor misunderstanding, I get it now. Thanks for clarification 👍
28th Feb 2019, 11:39 AM
Ipang
+ 2
Syed Kumail Hussain Sherazi a moderator changed it to that, because he thought it could possibly be someones real phonenumber. The original value looked like a phonenumber.
2nd Mar 2019, 8:05 AM
Seb TheS
Seb TheS - avatar
+ 1
Because it might have too big value to be an int.
28th Feb 2019, 10:05 AM
Seb TheS
Seb TheS - avatar
+ 1
You might change int heading to long, or long long
28th Feb 2019, 10:08 AM
Seb TheS
Seb TheS - avatar
+ 1
Thanks a lot guys!
28th Feb 2019, 10:29 AM
Thokgamo Shadreck
Thokgamo Shadreck - avatar
+ 1
I wanted to display a number so I edited the code from the tutorial and named it "int myPhone" instead of "int a" and picked a random 10 digit number. I think the admins thought it was my real number and changed it to "2^12" and added those comments in the asterix. It wasnt a working phone number (that I know of) but sorry for the confusion guys.
28th Feb 2019, 11:30 AM
Thokgamo Shadreck
Thokgamo Shadreck - avatar
+ 1
The issue isn't limit. What ^ does is actually bitwise XOR operation. So binary of 2 = 0010, and binary of 12 = 1100, if we do bitwise XOR the answer is: 1110 (which is 14 in denary). You might want to look into std::pow(). A lot of scripting languages use ^ as power operator, C++ doesn't.
2nd Mar 2019, 1:52 AM
Syed Kumail Hussain Sherazi
Syed Kumail Hussain Sherazi - avatar
0
Thanks
28th Feb 2019, 10:06 AM
Thokgamo Shadreck
Thokgamo Shadreck - avatar
0
Oh lol. My bad.
2nd Mar 2019, 11:27 AM
Syed Kumail Hussain Sherazi
Syed Kumail Hussain Sherazi - avatar