[New-bugs-announce] [issue28553] int.to_bytes docs logic error
Ofek Lev
report at bugs.python.org
Fri Oct 28 20:08:04 EDT 2016
New submission from Ofek Lev:
https://docs.python.org/3/library/stdtypes.html#int.to_bytes
To convert an int to the exact number of bytes required, the docs recommend "x.to_bytes((x.bit_length() // 8) + 1, ...)". This is incorrect when length is a multiple of 8, e.g. 296.
The correct way is "x.to_bytes((x.bit_length() + 7) // 8, ...)".
----------
assignee: docs at python
components: Documentation
messages: 279641
nosy: Ofekmeister, docs at python
priority: normal
severity: normal
status: open
title: int.to_bytes docs logic error
type: enhancement
versions: Python 3.3, Python 3.4, Python 3.5, Python 3.6, Python 3.7
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue28553>
_______________________________________
More information about the New-bugs-announce
mailing list