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

  • Home
  • SEARCH
  • 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 164261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:42:46+00:00 2026-05-11T11:42:46+00:00

Possible Duplicate: Is there a printf converter to print in binary format? Still learning

  • 0

Possible Duplicate:
Is there a printf converter to print in binary format?

Still learning C and I was wondering:

Given a number, is it possible to do something like the following?

char a = 5; printf('binary representation of a = %b',a); > 101 

Or would i have to write my own method to do the transformation to binary?

  • 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. 2026-05-11T11:42:47+00:00Added an answer on May 11, 2026 at 11:42 am

    Yes (write your own), something like the following complete function.

    #include <stdio.h> /* only needed for the printf() in main(). */ #include <string.h>  /* Create a string of binary digits based on the input value.    Input:        val:  value to convert.        buff: buffer to write to must be >= sz+1 chars.        sz:   size of buffer.    Returns address of string or NULL if not enough space provided. */ static char *binrep (unsigned int val, char *buff, int sz) {     char *pbuff = buff;      /* Must be able to store one character at least. */     if (sz < 1) return NULL;      /* Special case for zero to ensure some output. */     if (val == 0) {         *pbuff++ = '0';         *pbuff = '\0';         return buff;     }      /* Work from the end of the buffer back. */     pbuff += sz;     *pbuff-- = '\0';      /* For each bit (going backwards) store character. */     while (val != 0) {         if (sz-- == 0) return NULL;         *pbuff-- = ((val & 1) == 1) ? '1' : '0';          /* Get next bit. */         val >>= 1;     }     return pbuff+1; } 

    Add this main to the end of it to see it in operation:

    #define SZ 32 int main(int argc, char *argv[]) {     int i;     int n;     char buff[SZ+1];      /* Process all arguments, outputting their binary. */     for (i = 1; i < argc; i++) {         n = atoi (argv[i]);         printf('[%3d] %9d -> %s (from '%s')\n', i, n,             binrep(n,buff,SZ), argv[i]);     }      return 0; } 

    Run it with 'progname 0 7 12 52 123' to get:

    [  1]         0 -> 0 (from '0') [  2]         7 -> 111 (from '7') [  3]        12 -> 1100 (from '12') [  4]        52 -> 110100 (from '52') [  5]       123 -> 1111011 (from '123') 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 115k
  • Answers 115k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer With anonymous users, you have two options, neither of which… May 11, 2026 at 10:29 pm
  • Editorial Team
    Editorial Team added an answer Check to see if the input has the class "hint".… May 11, 2026 at 10:29 pm
  • Editorial Team
    Editorial Team added an answer It seems that what I was trying to do is… May 11, 2026 at 10:29 pm

Related Questions

Possible Duplicate: Is there a good reason to use upper case for T-SQL keywords?
Possible Duplicate: Is there a way for MS Access to grab the current Active
Possible Duplicate: C# - Is there a better alternative than this to ‘switch on
Possible Duplicate: What is the difference between "typename" and "class" template parameters? When defining

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.