public static void main(String[] args) {
ArrayList arr = new ArrayList();
int binary = Integer.parseInt(args[0]);
int dec = 0, count = 0;
while (binary > 0) {
if (binary % 10 > 0) {
dec += Math.pow(2, count);
}
binary = binary / 10;
count++;
}
while (dec > 0) {
arr.add(dec % 8);
dec = dec / 8;
}
for (int i = arr.size() – 1; i >= 0; i–) {
System.out.print(arr.get(i));
}
int main()
{
int num,call;
int arr[100];
int count=0;
int i=0;
scanf(“%d”,&num);
num=b_to_d(num);
while(num!=0)
{
arr[i]=num%8;
num=num/8;
i++;
}
for(int j=i-1;j>=0;j–)
{
printf(“%d”,arr[j]);
}
return 0;
}
int b_to_d(int input)
{
int i=0;
int num=0;
while(input!=0)
{
num=num+(input%10)*pow(2,i);
input=input/10;
i++;
}
return num;
}
// Online C compiler to run C program online
#include
int main() {
int x,n,a[20],rem,p;
int sum=0;
int count=0,i=0;
printf(“enter the number :”);
scanf(“%d”,&x);
//binary to deciamal
p=1;
while(x>0){
rem=x%10;
sum=sum+(rem*p);
p*=2;
x=x/10;
i++;
}
n=sum;
arr=[int(i) for i in input()]
if len(arr)%3!=0:
extraZeroToAdd=len(arr)%3
for i in range(3-extraZeroToAdd):
arr.insert(0,0)
size=len(arr)//3
res=[]
for i in range(int(size)):
c=2
sum=0
while c>=0:
if(arr[0]==1):
sum=sum+2**c
c=c-1
arr.pop(0)
res.append(sum)
public class BinaryToOctal {
public static void main(String[] args) {
System.out.println(binToOct(“101001”));
}
static int binToOct(String number) {
int dec = Integer.parseInt(number , 2);
int oct = Integer.parseInt(Integer.toOctalString(dec));
return oct;
}
}
n=111
res=0
i=0
while(n!=0):
res=res+pow(2,i*n%10)
n=n//10
i+=1
print(res)
n=input()
k=n[::-1]
dec=0
for i in range(len(k)):
if k[i]==’1′:
dec=dec+2**i
x=str(oct(dec))
print(x[2:])
n=input()
c=int(n,2)
c1=str(oct(c))
print(c1[2:])
public static void main(String[] args) {
ArrayList arr = new ArrayList();
int binary = Integer.parseInt(args[0]);
int dec = 0, count = 0;
while (binary > 0) {
if (binary % 10 > 0) {
dec += Math.pow(2, count);
}
binary = binary / 10;
count++;
}
while (dec > 0) {
arr.add(dec % 8);
dec = dec / 8;
}
for (int i = arr.size() – 1; i >= 0; i–) {
System.out.print(arr.get(i));
}
}
int main()
{
int num,call;
int arr[100];
int count=0;
int i=0;
scanf(“%d”,&num);
num=b_to_d(num);
while(num!=0)
{
arr[i]=num%8;
num=num/8;
i++;
}
for(int j=i-1;j>=0;j–)
{
printf(“%d”,arr[j]);
}
return 0;
}
int b_to_d(int input)
{
int i=0;
int num=0;
while(input!=0)
{
num=num+(input%10)*pow(2,i);
input=input/10;
i++;
}
return num;
}
// Online C compiler to run C program online
#include
int main() {
int x,n,a[20],rem,p;
int sum=0;
int count=0,i=0;
printf(“enter the number :”);
scanf(“%d”,&x);
//binary to deciamal
p=1;
while(x>0){
rem=x%10;
sum=sum+(rem*p);
p*=2;
x=x/10;
i++;
}
n=sum;
//decimal to octal
i=0;
count=0;
while(n>0){
rem=n%8;
a[i]=rem;
n=n/8;
i++;
count++;
}
for(i=count-1;i>=0;i–){
printf(“%d”,a[i]);
}
return 0;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner s=new Scanner(System.in);
String s1=s.nextLine();
String[] s2=s1.split(“”);
ArrayList arrList=new ArrayList();
ArrayList res=new ArrayList();
for(String i:s2) {
arrList.add(Integer.parseInt(i));
}
System.out.println(Math.pow(2,2));
Math.pow(4, 3);
if(arrList.size()%3!=0) {
int m = arrList.size()%3;
int k=3-m;
for(int i=0;i<k;i++) {
arrList.add(i,0);
}
}
int size=arrList.size()/3;
for(int i=0;i=0) {
if(arrList.get(0)==1) {
sum+= Math.pow(2,p);
}
arrList.remove(0);
p-=1;
}
res.add(sum);
} System.out.println(res);
int index=0;
for(float i:res) {
arrList.add(0, (int) i);
index+=1;
}
Collections.reverse(arrList);
for(int i:arrList) {
System.out.print(i);
}
}
arr=[int(i) for i in input()]
if len(arr)%3!=0:
extraZeroToAdd=len(arr)%3
for i in range(3-extraZeroToAdd):
arr.insert(0,0)
size=len(arr)//3
res=[]
for i in range(int(size)):
c=2
sum=0
while c>=0:
if(arr[0]==1):
sum=sum+2**c
c=c-1
arr.pop(0)
res.append(sum)
print(”.join(str(i) for i in res))
public class BinaryToOctal {
public static void main(String[] args) {
System.out.println(binToOct(“101001”));
}
static int binToOct(String number) {
int dec = Integer.parseInt(number , 2);
int oct = Integer.parseInt(Integer.toOctalString(dec));
return oct;
}
}
c=0
s=0
n=int(input(“Enter number:”))
while n > 0:
r=int(n%10)
p=pow(8,c)
s=s+(r*p)
n=int(n/10)
c=c+1
print(s)
Thanks for contributing your code Febin
#python
binary = input(“Enter any number in Binary Format: “);
if binary == ‘x’:
exit();
else:
temp = int(binary, 2);
p=oct(temp)
a=p.replace(“0o”,””)
print(a)
Thanks for contributing the code Bathula
#python
binary = input(“Enter any number in Binary Format: “);
if binary == ‘x’:
exit();
else:
temp = int(binary, 2);
print(temp)
p=oct(temp)
a=p.replace(“0o”,””)
print(a)
Thanks for contributing the code Bathula