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 1107005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:52:32+00:00 2026-05-17T01:52:32+00:00

While reading a book called Let us C I read that a function showbit()

  • 0

While reading a book called “Let us C” I read that a function showbit() exists which can show you the bits of the number. There wasn’t any special header file mentioned for it. Searched for it on the internet and didn’t found anything useful. Is there such a function? I want this to print the binary of decimal numbers. Else please give me a replacement function. Thanks

  • 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-05-17T01:52:33+00:00Added an answer on May 17, 2026 at 1:52 am

    All integers are actually in binary in your computer. Its just that it is turned into a string that is the decimal representation of that value when you try to print it using printf and “%d”. If you want to know what it looks like in some other base (e.g. base 2 or binary), you either have to provide the proper printf format string if it exists (e.g. “%x” for hex) or just build that string yourself and print it out.

    Here is some code that can build the string representation of an integer in any base in [2,36].

    #include <stdio.h>
    #include <string.h>
    
    char digits[]="01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    
    void reverse(char* start, char* end)
    {
        for(end--;start<end;start++,end--)
        {
            char t=*start;
            *start=*end;
            *end=t;
        }
    }
    
    
    int base_change(int n, int base,char* buffer)
    {
        int pos=0;
        if (base>strlen(digits)) 
            return -1;
        while(n)
        {
            buffer[pos]=digits[n%base];
            n/=base;
            pos++;
        }
        buffer[pos]='\0';
        reverse(buffer,buffer+pos);
        return 0;
    }
    
    int main()
    {
        char buffer[32];
        int conv=base_change(1024,2,buffer);
        if (conv==0) printf("%s\n",buffer);
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'am novice in JS. While reading the book, I found that some examples do
I have an app which is like reading a book, and while reading if
while I was reading a javascript book, I read the following sentence. The call
While reading a book on C#, I have come across code that uses the
While reading the book Programming Ruby , one example shows how blocks can be
I have written a small program, while reading a book about swing, that creates
While reading a book about JavaScript I stumbled across an example: var names =
While reading this class BitmapFactory I noticed that almost all methods inside are static.
While reading the K&R 2nd edition I noticed that the programs always began with
While reading from serial port I am using serialport.read(xyz,0,4) where xyz is a byte

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.