Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5cd7520

Browse files
committed
Describe new ("unsigned") behavior of hex() and oct().
1 parent 9a0313c commit 5cd7520

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

Doc/lib/libfuncs.tex

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,12 @@ \section{Built-in Functions}
189189

190190
\begin{funcdesc}{hex}{x}
191191
Convert an integer number (of any size) to a hexadecimal string.
192-
The result is a valid Python expression.
192+
The result is a valid Python expression. Note: this always yields
193+
an unsigned literal, e.g. on a 32-bit machine, \code{hex(-1)} yields
194+
\code{'0xffffffff'}. When evaluated on a machine with the same
195+
word size, this literal is evaluated as -1; at a different word
196+
size, it may turn up as a large positive number or raise an
197+
\code{OverflowError} exception.
193198
\end{funcdesc}
194199

195200
\begin{funcdesc}{id}{object}
@@ -256,7 +261,12 @@ \section{Built-in Functions}
256261

257262
\begin{funcdesc}{oct}{x}
258263
Convert an integer number (of any size) to an octal string. The
259-
result is a valid Python expression.
264+
result is a valid Python expression. Note: this always yields
265+
an unsigned literal, e.g. on a 32-bit machine, \code{oct(-1)} yields
266+
\code{'037777777777'}. When evaluated on a machine with the same
267+
word size, this literal is evaluated as -1; at a different word
268+
size, it may turn up as a large positive number or raise an
269+
\code{OverflowError} exception.
260270
\end{funcdesc}
261271

262272
\begin{funcdesc}{open}{filename\optional{\, mode\optional{\, bufsize}}}

Doc/libfuncs.tex

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,12 @@ \section{Built-in Functions}
189189

190190
\begin{funcdesc}{hex}{x}
191191
Convert an integer number (of any size) to a hexadecimal string.
192-
The result is a valid Python expression.
192+
The result is a valid Python expression. Note: this always yields
193+
an unsigned literal, e.g. on a 32-bit machine, \code{hex(-1)} yields
194+
\code{'0xffffffff'}. When evaluated on a machine with the same
195+
word size, this literal is evaluated as -1; at a different word
196+
size, it may turn up as a large positive number or raise an
197+
\code{OverflowError} exception.
193198
\end{funcdesc}
194199

195200
\begin{funcdesc}{id}{object}
@@ -256,7 +261,12 @@ \section{Built-in Functions}
256261

257262
\begin{funcdesc}{oct}{x}
258263
Convert an integer number (of any size) to an octal string. The
259-
result is a valid Python expression.
264+
result is a valid Python expression. Note: this always yields
265+
an unsigned literal, e.g. on a 32-bit machine, \code{oct(-1)} yields
266+
\code{'037777777777'}. When evaluated on a machine with the same
267+
word size, this literal is evaluated as -1; at a different word
268+
size, it may turn up as a large positive number or raise an
269+
\code{OverflowError} exception.
260270
\end{funcdesc}
261271

262272
\begin{funcdesc}{open}{filename\optional{\, mode\optional{\, bufsize}}}

0 commit comments

Comments
 (0)