Computing.Net > Forums > Programming > binary representation in C

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

binary representation in C

Reply to Message Icon

Name: guillaume
Date: July 3, 2003 at 02:41:34 Pacific
OS: solaris
CPU/Ram: unknown
Comment:

Hi,I need some help in C:

I have a double U between 0 and 1 and I need b0,b1,....,bt where U=(.b0b1b3....bt) is the binary representation of U.
is there any command in C that allow to get them?

Thank you for your help.



Sponsored Link
Ads by Google

Response Number 1
Name: bitbyte
Date: July 3, 2003 at 09:52:37 Pacific
Reply:

=================================================

hi, i dont know if that is really what you want to do

example value is 0xf1
output is b1,b0,b0,b0,b1,b1,b1,b1,b0....

#include <stdio.h>
#include <string.h>
int main() {
//
long val=0xf1; // value to view
char outstr[256]; // output string
//
  for (int i=0;i<32;i++) {
      if (val & 1) strcat (outstr,"b1,"); //test bit is 0 or 1
      else strcat (outstr,"b0,");
      val>>=1; // shift right to test next bit

  }
  printf ("%s\n",outstr); // output of string
}


0

Response Number 2
Name: guillaume
Date: July 3, 2003 at 13:19:10 Pacific
Reply:

thank you


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: binary representation in C

representing binary number in C www.computing.net/answers/programming/representing-binary-number-in-c/3346.html

Binary Search in C. Help Please! www.computing.net/answers/programming/binary-search-in-c-help-please/6847.html

Number to Binary in C? www.computing.net/answers/programming/number-to-binary-in-c/9326.html