This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Ofekmeister
Recipients Ofekmeister, docs@python
Date 2016-10-29.00:08:03
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1477699684.07.0.61979939957.issue28553@psf.upfronthosting.co.za>
In-reply-to
Content
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, ...)".
History
Date User Action Args
2016-10-29 00:08:04Ofekmeistersetrecipients: + Ofekmeister, docs@python
2016-10-29 00:08:04Ofekmeistersetmessageid: <1477699684.07.0.61979939957.issue28553@psf.upfronthosting.co.za>
2016-10-29 00:08:04Ofekmeisterlinkissue28553 messages
2016-10-29 00:08:03Ofekmeistercreate