View previous topic :: View next topic |
Author |
Message |
hamid9543
Joined: 31 Jan 2013 Posts: 63
|
printf binary format |
Posted: Sat Apr 24, 2021 12:15 pm |
|
|
unsigned int8 a; (or int16)
How to print binary number via printf ? |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1941 Location: Norman, OK
|
|
|
hamid9543
Joined: 31 Jan 2013 Posts: 63
|
|
Posted: Sun Apr 25, 2021 12:10 pm |
|
|
I searched but i don't found anythings!!! how you search in forum ? I searched "printf binary format" |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9287 Location: Greensville,Ontario
|
|
Posted: Sun Apr 25, 2021 12:40 pm |
|
|
hmm.
in the search box... 'printf binary format'
select 'search for all terms'
produces 69 'hits' for me |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19609
|
|
Posted: Mon Apr 26, 2021 1:32 am |
|
|
Problem is that by default, the search is set to 'search for any term', which
means it will give thousands of hits that have nothing to do with what is
required. The other issue, is that actually the 'answer' is nothing to do
with printf. Printf itself has no binary output form. What the compiler has
is the standard C function that allows you to output a value into any
numeric format. If you searched for 'binary string format', and 'search for
all terms', the very first hit contains the 'answer'.
In fact the other very powerful way to search is to use Google.
Put into this:
forum:ccsinfo.com binary number output
The whole first page is full of correct answers. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9287 Location: Greensville,Ontario
|
|
Posted: Mon Apr 26, 2021 5:27 am |
|
|
hmm, I have to wonder, why CCS doesn't have the 'print in binary format' option for the printf() function ? It's kinda the 'base' level way to display 'data'....ones and zeros, bit by bit...... |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19609
|
|
Posted: Mon Apr 26, 2021 5:45 am |
|
|
Basically because it was not part of C.
K&R obviously did not expect anyone to actually want to do this.
The capability is there to do this with itoa, as part of a more generic
ability to output data in any numeric format, but was never a printf
formatter. |
|
|
|