summaryrefslogtreecommitdiff
path: root/rsa
diff options
context:
space:
mode:
authorYesudeep Mangalapilly <yesudeep@gmail.com>2011-08-24 16:04:32 +0530
committerYesudeep Mangalapilly <yesudeep@gmail.com>2011-08-24 16:04:32 +0530
commit3f38343bf048266883124715a1e3be27e551defa (patch)
tree0bed19da0f4c96fd150b0626890d80c31192a997 /rsa
parent5d80d140efb0999e02a4f440b0131eb335c1b229 (diff)
downloadrsa-3f38343bf048266883124715a1e3be27e551defa.tar.gz
Adds the doctests for bit_size back into the function docstrings.
Diffstat (limited to 'rsa')
-rw-r--r--rsa/common.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/rsa/common.py b/rsa/common.py
index eb95e82..8667087 100644
--- a/rsa/common.py
+++ b/rsa/common.py
@@ -25,6 +25,15 @@ def bit_size(num):
As per definition from http://wiki.python.org/moin/BitManipulation and
to match the behavior of the Python 3 API.
+ Usage::
+
+ >>> bit_size(1023)
+ 10
+ >>> bit_size(1024)
+ 11
+ >>> bit_size(1025)
+ 11
+
:param num:
Integer value. If num is 0, returns 0. Only the absolute value of the
number is considered. Therefore, signed integers will be abs(num)
@@ -74,6 +83,20 @@ def byte_size(number):
Returns the number of bytes required to hold a specific long number.
The number of bytes is rounded up.
+
+ Usage::
+
+ >>> byte_size(1 << 1023)
+ 128
+ >>> byte_size((1 << 1024) - 1)
+ 128
+ >>> byte_size(1 << 1024)
+ 129
+
+ :param number:
+ An unsigned integer
+ :returns:
+ The number of bytes required to hold a specific long number.
"""
quanta, mod = divmod(bit_size(number), 8)
if mod or number == 0: