From 9555d7b5bd145a5353d8ce1bda6e0819a0b74169 Mon Sep 17 00:00:00 2001 From: Prodesire Date: Wed, 10 Jan 2018 00:31:59 +0800 Subject: [PATCH] update doc for convert --- docs/convert.rst | 120 +++++++++++++++++++++++++++++++++++++++++++++++ pydu/convert.py | 2 +- 2 files changed, 121 insertions(+), 1 deletion(-) diff --git a/docs/convert.rst b/docs/convert.rst index db3ca37..dd02c5d 100644 --- a/docs/convert.rst +++ b/docs/convert.rst @@ -19,3 +19,123 @@ Convert True >>> boolean('no') False + + +.. py:function:: pydu.convert.bin2oct(x) + + Convert binary string to octal string. + For instance: '1001' -> '11' + + >>> from pydu.convert import bin2oct + >>> bin2oct('1001') + '11' + + +.. py:function:: pydu.convert.bin2dec(x) + + Convert binary string to decimal number. + For instance: '11' -> 3 + + >>> from pydu.convert import bin2dec + >>> bin2dec('11') + 3 + + +.. py:function:: pydu.convert.bin2hex(x) + + Convert binary string to hexadecimal string. + For instance: '11010' -> '1a' + + >>> from pydu.convert import bin2hex + >>> bin2hex('11010') + '1a' + + +.. py:function:: pydu.convert.oct2bin(x) + + Convert octal string to binary string. + For instance: '11' -> '1001' + + >>> from pydu.convert import oct2bin + >>> oct2bin('11') + '1001' + + +.. py:function:: pydu.convert.oct2dec(x) + + Convert octal string to decimal number. + For instance: '11' -> 9 + + >>> from pydu.convert import oct2dec + >>> oct2dec('11') + 9 + + +.. py:function:: pydu.convert.oct2hex(x) + + Convert octal string to hexadecimal string. + For instance: '32' -> '1a' + + >>> from pydu.convert import oct2hex + >>> oct2hex('32') + '1a' + + +.. py:function:: pydu.convert.dec2bin(x) + + Convert decimal number to binary string. + For instance: 3 -> '11' + + >>> from pydu.convert import dec2bin + >>> dec2bin(3) + '11' + + +.. py:function:: pydu.convert.dec2oct(x) + + Convert decimal number to octal string. + For instance: 9 -> '11' + + >>> from pydu.convert import dec2oct + >>> dec2oct(9) + '11' + + +.. py:function:: pydu.convert.dec2hex(x) + + Convert decimal number to hexadecimal string. + For instance: 26 -> '1a' + + >>> from pydu.convert import dec2hex + >>> dec2hex(26) + '1a' + + +.. py:function:: pydu.convert.hex2bin(x) + + Convert hexadecimal string to binary string. + For instance: '1a' -> '11010' + + >>> from pydu.convert import hex2bin + >>> hex2bin('1a') + '11010' + + +.. py:function:: pydu.convert.hex2oct(x) + + Convert hexadecimal string to octal string. + For instance: '1a' -> '32' + + >>> from pydu.convert import hex2oct + >>> hex2oct('1a') + '32' + + +.. py:function:: pydu.convert.hex2dec(x) + + Convert hexadecimal string to decimal number. + For instance: '1a' -> 26 + + >>> from pydu.convert import hex2dec + >>> hex2dec('1a') + 26 diff --git a/pydu/convert.py b/pydu/convert.py index e1b4fb3..e9e36c1 100644 --- a/pydu/convert.py +++ b/pydu/convert.py @@ -100,7 +100,7 @@ def dec2oct(x): def dec2hex(x): """ Convert decimal number to hexadecimal string. - For instance: 2 -> '10' + For instance: 26 -> '1a' """ return hex(x)[2:]