Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8749759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:44:53+00:00 2026-06-13T12:44:53+00:00

This program is to convert a base 4 number to a base 2 number

  • 0

This program is to convert a base 4 number to a base 2 number and it should be done in place

#include<stdio.h>
#include<string.h>

void shiftr(char num[],int i)
{
     memmove(num+i,num+i+1,strlen(num)-i);
}

char* convert4to2(char num[])
{
int i=0,len;
char ch;

    while(num[i]!='\0')
    {
        ch=num[i];
        shiftr(num,i);
        switch(ch)
        {
            case '0':num[i++]='0';
                 num[i++]='0';
                 break;

            case '1':num[i++]='0';
                 num[i++]='1';
                 break;

            case '2':num[i++]='1';
                 num[i++]='0';
                 break;

            case '3':num[i++]='1';
                 num[i++]='1';
                 break;

            default:printf("Error");
        }
    }

    num[i]='\0';
    return(num);
}



void main()
{
    char num[20];
    printf("Enter the Base 4 Number:");
    scanf("%s",&num);
    printf("The Binary Equivalent is:%s\n",convert4to2(num));   
}

The output for an input of 121(base 4 number) should be 011001 but its displaying only 01.
And for larger numbers like 12101 it displays 0100 taking the first and the last but one numeral.
What could be the problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:44:54+00:00Added an answer on June 13, 2026 at 12:44 pm

    You’re actively destroying your input. E.g., for the first iteration, you shift your number by one place and after that you overwrite the data at place 0 and place 1 (which contains the next 2 digits in 4-base) with your binary output for the 1st digit.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make this program in assembly. It should just convert a string
#include <stdio.h> #include <math.h> long int input; long int base, exponent; void convert(long int
This is the program to convert a number into different representations like octal,decimal,hexadecimal etc.
I'm trying to make a program to convert a number in any base to
This program stores pairs in a map, counting the number of times a word
I have this program that is feeding me data. I take this data (string)
So I have this program to convert a binary to hex. I also have
This program builds a dictionary out of a list based on what two index
This program returns: package main import ( flag fmt ) func main() { num_agents
This program runs just fine, but for some reason when I ask for an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.