Decimal to Octal on Hacker Blocks

I wrote this code but the output coming is wrong .Can you please explain where I am getting wrong ?

#include
using namespace std;
int main() {
int n;
int m=0;
int k;
int p=1;
int g=0;
cin>>n;
while (n>0)
{
k=n%8;
p=10^g;
m=m+k*p;
g=g+1;
n=n/8;
}
cout<<m<<endl;

return 0;

}

Please save your code on ide.codingblocks.com and then share its link.

Check line 14 of your code.
In C++ the “^” operator is a bitwise OR. It does not work for raising to a power.
The logic is also very simple:
You can refer this

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

In C++ the “^” operator is a bitwise OR, so how to raise a power of something in C++

Hi @abhix25

You can use inbuilt pow function. Syntax -> int ans = pow(x,y); x raised to power y is stored in variable ans.

Hope it Helps.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.