LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

print in binary format

uint8 value = 5;
The "value" in binary format is "101".  How can I print it in binary format?  Anyone can help?  Thanks!
0 Kudos
Message 1 of 3
(3,165 Views)
The following code is targetted at converting a single byte into binary and setting a CVI string control accordingly, but I'm sure you will be able to adapt its ideas to suit your application:

//*****************************************************************************************
void ShowBin (int ctrl, int val) {      // Display data in binary
 
    char str [9];
    int i, patt = 0x80;
 
    str [8] = 0;                        // Terminate string
    for (i = 0; i < 8; i++, patt >>= 1) // Repeat for each bit
        str [i] = val & patt ? '1': '0';    // Select a 1 or a 0                          
    SetCtrlVal (pan, ctrl, str);        // Update display
}
//*****************************************************************************************

JR
0 Kudos
Message 2 of 3
(3,161 Views)
> uint8 value = 5; The "value" in binary format is "101".&nbsp;
> How can I print it in binary format?&nbsp; Anyone can help?&nbsp; Thanks!

So standard printf specifier, unfortunately.

See Question 20.10 in the comp.lang.c Frequently Asked
Questions (FAQ) list at http://www.c-faq.com/.
--
Guillaume Dargaud
http://www.gdargaud.net/


0 Kudos
Message 3 of 3
(3,146 Views)