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@python
components: Documentation
messages: 279641
nosy: Ofekmeister, docs@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 <rep...@bugs.python.org>
<http://bugs.python.org/issue28553>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to