Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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.

=================================================
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
}

![]() |
![]() |
![]() |

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