473,377 Members | 1,151 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,377 software developers and data experts.

printf("%#04x\n", 0); print 0000 not 0x00

hi all,

i hope
printf("%#04x\n", 0);
will output 0x00,
but visual c++ studio 6 outputs 0000.

how can i get 0x00?

thanks

Nov 15 '05 #1
8 13592
printf("0x%#02x", 0);

baumann@pan wrote:
hi all,

i hope
printf("%#04x\n", 0);
will output 0x00,
but visual c++ studio 6 outputs 0000.

how can i get 0x00?

thanks


Nov 15 '05 #2
On 30 Jun 2005 18:44:21 -0700, "baumann@pan" <as*******@hotmail.com>
wrote in comp.lang.c:
hi all,

i hope
printf("%#04x\n", 0);
will output 0x00,
but visual c++ studio 6 outputs 0000.

how can i get 0x00?

thanks


By coding:

printf("0x%04x\n", 0U);

There is no way to get printf() to do what you want with the format
string you are using and a value of 0, since it obviously does not
want to. Here is what the C standard says about the '#' flag:

"For x (or X) conversion, a nonzero result has 0x (or 0X) prefixed to
it."

That does not prevent an implementation from putting 0x in front of
the output for a value of 0, but it also most certainly does not
require it to do so.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 15 '05 #3
Jack Klein wrote:
"baumann@pan" <as*******@hotmail.com> wrote in comp.lang.c:
hi all,

i hope
printf("%#04x\n", 0);
will output 0x00,
but visual c++ studio 6 outputs 0000.

how can i get 0x00?

thanks
By coding:

printf("0x%04x\n", 0U);


ITYM: printf("0x%02x\n", 0U);
<snip>


--
Peter

Nov 15 '05 #4
On 30 Jun 2005 19:35:19 -0700, "Ganesh babu" <ga*********@gmail.com>
wrote in comp.lang.c:
printf("0x%#02x", 0);

baumann@pan wrote:
hi all,

i hope
printf("%#04x\n", 0);
will output 0x00,
but visual c++ studio 6 outputs 0000.

how can i get 0x00?

thanks


....but note that the wording of the standard does not prohibit an
implementation from prepending a "0x" even if the value is 0. So on
some implementations you might get "0x0x00".

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 15 '05 #5
On 30 Jun 2005 20:00:50 -0700, "Peter Nilsson" <ai***@acay.com.au>
wrote in comp.lang.c:
Jack Klein wrote:
"baumann@pan" <as*******@hotmail.com> wrote in comp.lang.c:
hi all,

i hope
printf("%#04x\n", 0);
will output 0x00,
but visual c++ studio 6 outputs 0000.

how can i get 0x00?

thanks


By coding:

printf("0x%04x\n", 0U);


ITYM: printf("0x%02x\n", 0U);


You are correct, sir. I misinterpreted the width of 4 in the OP's
original. Thanks.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 15 '05 #6
On Thu, 30 Jun 2005 22:58:29 -0500, Jack Klein wrote:
On 30 Jun 2005 19:35:19 -0700, "Ganesh babu" <ga*********@gmail.com>
wrote in comp.lang.c:
printf("0x%#02x", 0);
Which will output for example 0x0x1 for an argument value of 1. If you
were only interested in 0 values you could write simply:

printf("0x00");
baumann@pan wrote:
> hi all,
>
> i hope
> printf("%#04x\n", 0);
> will output 0x00,
> but visual c++ studio 6 outputs 0000.
>
> how can i get 0x00?
>
> thanks

...but note that the wording of the standard does not prohibit an
implementation from prepending a "0x" even if the value is 0.


I can't see anything in the standard that permits it to prepend 0x for a 0
value.
So on
some implementations you might get "0x0x00".


The # flag specifies an alterative form. It is described in terms of how
it differs from the primary form. For a 0 value there is no difference
specified. You seem to be saying that the output for a 0 value is not
specified. If that is true the output could be anything at all which would
make %#x useless for outputting 0 values.

Lawrence
Nov 15 '05 #7
On Fri, 01 Jul 2005 12:12:11 +0100, Lawrence Kirby
<lk****@netactive.co.uk> wrote in comp.lang.c:
On Thu, 30 Jun 2005 22:58:29 -0500, Jack Klein wrote:
On 30 Jun 2005 19:35:19 -0700, "Ganesh babu" <ga*********@gmail.com>
wrote in comp.lang.c:
printf("0x%#02x", 0);
Which will output for example 0x0x1 for an argument value of 1. If you
were only interested in 0 values you could write simply:

printf("0x00");
baumann@pan wrote:
> hi all,
>
> i hope
> printf("%#04x\n", 0);
> will output 0x00,
> but visual c++ studio 6 outputs 0000.
>
> how can i get 0x00?
>
> thanks


...but note that the wording of the standard does not prohibit an
implementation from prepending a "0x" even if the value is 0.


I can't see anything in the standard that permits it to prepend 0x for a 0
value.


I don't see anything that forbids it. It says "For x (or X)
conversion, a nonzero result has 0x (or 0X) prefixed to it." It does
not say anything at all about a result that is not nonzero.
So on
some implementations you might get "0x0x00".


The # flag specifies an alterative form. It is described in terms of how
it differs from the primary form. For a 0 value there is no difference
specified. You seem to be saying that the output for a 0 value is not
specified. If that is true the output could be anything at all which would
make %#x useless for outputting 0 values.

Lawrence


To me it looks like one of those cases where the wording in the
standard leaves a loop hole. Typical standardese, as one is likely to
see if one brings up such issues on comp.std.c, is that since the
standard specifically defines behavior for the nonzero case and does
not define behavior for the 0 case, the 0 case is undefined.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 15 '05 #8
On Fri, 01 Jul 2005 22:18:49 -0500, Jack Klein wrote:
The # flag specifies an alterative form. It is described in terms of how
it differs from the primary form. For a 0 value there is no difference
specified. You seem to be saying that the output for a 0 value is not
specified. If that is true the output could be anything at all which would
make %#x useless for outputting 0 values.

Lawrence


To me it looks like one of those cases where the wording in the
standard leaves a loop hole. Typical standardese, as one is likely to
see if one brings up such issues on comp.std.c, is that since the
standard specifically defines behavior for the nonzero case and does
not define behavior for the 0 case, the 0 case is undefined.


I agree, the wording could be improved.

Lawrence

Nov 15 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: John | last post by:
I am having a problem with window.print in a popup window. I am creating 2 popup windows both with a print button in them, 1 works the other doesn't. Code runs in a javascript function on a...
3
by: Joseph Suprenant | last post by:
Quick question hope someone can help. I am sending a file accross a radio, i am limited to using only chars. I get all the data on the receiving end but everytime it gets a 0x00 it is treated as...
2
by: billiejoex | last post by:
Hi all. I'm using pcapy module to sniff some ICMP packets. I would like to modify this source: http://www.google.it/search?hl=it&q=pcapy&btnG=Cerca+con+Google&meta= and visualize only the DATA...
3
by: Don | last post by:
Hi NG. I have the code below my question. I would like to copy the content of measuredata to the MyBuffer from place nr 20 (MyBuffer). The problem with this code is that between the two structs I...
6
by: jasn | last post by:
Hello I am getting the following error message when I try and send an XML sting to a web service, I read somewhere that most web services prefer ascii and some throw errors when using unicode so...
7
by: Rithish | last post by:
Hello. I noticed a strange thing while using strtotime() and date() functions in combination to generate from MySQL into a readable format. By default, the MySQL date field will be 0000-00-00...
69
by: Edward K Ream | last post by:
The pros and cons of making 'print' a function in Python 3.x are well discussed at: http://mail.python.org/pipermail/python-dev/2005-September/056154.html Alas, it appears that the effect of...
21
by: arnuld | last post by:
I have created a program to print the input words on stdout. Input is taken dynamically from stdin. In each word, each input character is allocated dynamically. I have ran this program with a file...
0
by: George Bush | last post by:
port2_result=os.popen('ipmitool raw 0x3a 0x11 0x2a 0x6f 0x00 8').read() this is the expression i've written in a script after calling a procedure to establish SSH connection to a remote machine. the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.