Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > sprintf

Reply
Thread Tools

sprintf

 
 
rockdale
Guest
Posts: n/a
 
      08-13-2009
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?

 
Reply With Quote
 
 
 
 
Jerry Coffin
Guest
Posts: n/a
 
      08-13-2009
In article <b24bc768-cec5-4c04-a329-c09576cda9a0
@h21g2000yqa.googlegroups.com>, says...
>
> 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.

--
Later,
Jerry.
 
Reply With Quote
 
 
 
 
Mug
Guest
Posts: n/a
 
      08-13-2009
On Aug 13, 8:15*pm, rockdale <rockdale.gr...@gmail.com> wrote:
> 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,
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a function similar to C++'s sprintf Pep Java 5 08-25-2005 08:23 PM
sprintf shea martin Java 5 09-03-2004 01:40 AM
difficulties with sprintf function Pilatus C++ 3 12-18-2003 07:00 PM
atoi: stringstream or old C sprintf function Mike Chirico C++ 2 11-19-2003 03:59 PM
String class, how to implement sprintf? CJ C++ 1 10-28-2003 10:54 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57