+ 2
Why it outputs 73 while it should output 0111
I also want to use it later in my programme please tell https://code.sololearn.com/cVe1nJ3Q1780/?ref=app
10 Respuestas
+ 13
Using 0 initially, makes it an octal value 111 which has a value of 73. See this table for more info :
http://ascii.cl/conversion.htm
EDIT - @Kirk Schafer explains it well ^^
+ 7
In many languages, numbers starting with 0 are interpreted as octal (base 8).
0111 = 0*8^3 + 1*8^2 + 1*8^1 + 1*8^0
(0 times 8³, 1 times 8², 1 times 8¹, 1 times 8°)
0 + 64 + 8 + 1 = 73
+ 3
bitset is really helpful
thabks ace
+ 3
Or just try :
cout<<oct<<l;
This will print 111, exactly what your number is...
//You see, 0 in a number in C++ makes the compiler think of it as an octal value...
If you wish to add like in binary, make a struct instead:
struct bin
{
int val;
bool sign;
};
// Then you may even overload operators for the same numbers...
/*
Then you may do :
bin a, b;
cout << a+b;
// Will print result of a + b in binary only...
*/
Use it then as you wish to...
+ 2
so what if I want to use 0111
as it is used in binary addition.as 1st bit of binary shows sign of the number and 0 is use for positive sign
+ 2
also tell me the shortest way of finding binary of some decimal number
+ 2
ace please explain your answer