# Comment about sprintf %u

**URL:** <https://www.ruby-forum.com/t/comment-about-sprintf-u/126816>\
**Category:** Development\
**Created:** [January 22, 2008, 3:24pm UTC](https://www.ruby-forum.com/t/comment-about-sprintf-u/126816 "2008-01-22T15:24:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yusuke\_ENDOH](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/c89c15/32.png) [@Yusuke\_ENDOH](https://www.ruby-forum.com/u/Yusuke_ENDOH)\
**Post date:** [January 22, 2008, 3:24pm UTC](https://www.ruby-forum.com/t/comment-about-sprintf-u/126816/1 "2008-01-22T15:24:44Z")

</div>

e$B1sF#$H?=$7$^$9!#e(B

r12809 e$B$+$ie(B sprintf e$B$Ne(B %u e$B$,e(B %d  
e$B$HF1$80UL#$K$J$C$?$h$&$G$9$,!"e(B  
e$B%3%a%s%H$,$=$l$KDI=\>$7$F$$$J$$$h$&$G$9!#e(B

# Index: sprintf.c

— sprintf.c (revision 15174)  
+++ sprintf.c (working copy)  
@@ -221,12 +221,7 @@

- 

```
   s | Argument is a string to be substituted. If the format

```

- 

```
       | sequence contains a precision, at most that many 

```

characters

- 

```
       | will be copied.

```

- 
  - 

```
   u | Treat argument as an unsigned decimal number. Negative 

```

integers

- 
  - 

```
       | are displayed as a 32 bit two's complement plus one for 

```

the

- 
  - 

```
       | underlying architecture; that is, 2 ** 32 + n. 

```

However, since

- 
  - 

```
       | Ruby has no inherent limit on bits used to represent 

```

the

- 
  - 

```
       | integer, this value is preceded by two dots (..) in 

```

order to

- 
  - 

```
       | indicate a infinite number of leading sign bits.

```

- 
  - 

```
   u | Identical to `d'.

```

  - 

```
   X | Convert argument as a hexadecimal number using 

```

uppercase

- 

```
       | letters. Negative numbers will be displayed with two

```

- 

```
       | leading periods (representing an infinite string of

```

@@ -243,7 +238,7 @@

- 

```
sprintf("%1$*2$s %2$d %1$s", "hello", 8) #=> " hello 8 

```

hello"

- 

```
sprintf("%1$*2$s %2$d", "hello", -8) #=> "hello -8"

```

- 

```
sprintf("%+g:% g:%-g", 1.23, 1.23, 1.23) #=> "+1.23: 

```

1.23:1.23"

- 
  - 

```
sprintf("%u", -123) #=> "..4294967173"

```

- 
  - 

```
sprintf("%u", -123) #=> "-123"

```

\*/

VALUE

---

<div class="post-metadata">

**Author:** ![Yusuke\_ENDOH](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/c89c15/32.png) [@Yusuke\_ENDOH](https://www.ruby-forum.com/u/Yusuke_ENDOH)\
**Post date:** [January 23, 2008, 4:50am UTC](https://www.ruby-forum.com/t/comment-about-sprintf-u/126816/2 "2008-01-23T04:50:33Z")

</div>

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:33275] comment about sprintf %u”  
on Tue, 22 Jan 2008 23:23:34 +0900, “Yusuke ENDOH” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
writes:

|r12809 e$B$+$ie(B sprintf e$B$Ne(B %u e$B$,e(B %d e$B$HF1$80UL#$K$J$C$?$h$&$G$9$,!"e(B  
|e$B%3%a%s%H$,$=$l$KDI=\>$7$F$$$J$$$h$&$G$9!#e(B

e$B%3%\_%C%H$7$F$/$@$5$$!#e(B
