sprintf

R

rockdale

just wondering, in its format, why it has signed and unsigned decimal
integer, signed octal, unsigned hexdecimal. ("%d", "%u", "%o", "%x")
but does not have unsigned octal and signed hexdecimal?
 
J

Jerry Coffin

just wondering, in its format, why it has signed and unsigned decimal
integer, signed octal, unsigned hexdecimal. ("%d", "%u", "%o", "%x")
but does not have unsigned octal and signed hexdecimal?

You've gotten things a bit wrong: it has signed and unsigned decimal.
Octal and hexadecimal are both (always) unsigned. The why seems to be
pretty simple: hex and octal are mostly used as compact
representations of bits, where sign is rarely desired.
 
M

Mug

just wondering, in its format, why it has signed and unsigned decimal
integer,  signed octal, unsigned hexdecimal. ("%d", "%u", "%o", "%x")
but does not have unsigned octal and signed hexdecimal?

yes they have but present differently:

#include <cstdio>

int main()
{
short x=-1;
printf("%d,%o,%x\n",x,x,x);
return 0;
}

zsh/2 3070 % ./a.out
-1,37777777777,ffffffff

for hex it's ffffffff,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,905
Latest member
Kristy_Poole

Latest Threads

Top