Python  1.0
Functions | Variables
_01d_dec2bin Namespace Reference

Converting between different numerical bases. More...

Functions

def Denary2Binary (num)
 Converts denary integer to a binary string. More...
 
def Binary2Denary (bStr)
 Converts a binary string to a denary integer. More...
 
def dec2hex (n)
 Converts a denary integer to hexadecimal. More...
 
def hex2dec (s)
 Converts a string or number to a plain integer. More...
 
def int2bin (n, count=24)
 Converts an integer to a binary string representation with an specified number of bits. More...
 
def main ()
 

Variables

 input = raw_input
 

Detailed Description

Converting between different numerical bases.

In a positional number system, the value of each digit is determined by which place it appears in the full number. The lowest place value is the rightmost position, and each successive position to the left has a higher place value.

For example, the value of the binary number 10011 is determined by computing the place value of each of the digits of the number:

            1          0          0          1          1       the binary number
            2⁴         2³         2²         2¹         2⁰      place values
         (1 * 2⁴) + (0 * 2³) + (0 * 2²) + (1 * 2¹) + (1 * 2⁰)
       =    16    +    0     +    0     +    2     +    1
       =    19
   
Author
Paulo Roma
Since
11/02/2009
See also
http://en.wikipedia.org/wiki/Binary_numeral_system

Function Documentation

◆ Binary2Denary()

def _01d_dec2bin.Binary2Denary (   bStr)

Converts a binary string to a denary integer.

Parameters
bStra binary string.
Returns
int(bStr,2).

Referenced by main().

◆ dec2hex()

def _01d_dec2bin.dec2hex (   n)

Converts a denary integer to hexadecimal.

Parameters
nan integer.
Returns
hex(n).

Referenced by main().

◆ Denary2Binary()

def _01d_dec2bin.Denary2Binary (   num)

Converts denary integer to a binary string.

Parameters
numan integer.
Returns
binary string.

Referenced by main().

◆ hex2dec()

def _01d_dec2bin.hex2dec (   s)

Converts a string or number to a plain integer.

The radix parameter gives the base for the conversion (which is 10 by default) and may be any integer in the range [2, 36], or zero. If radix is zero, the proper radix is determined based on the contents of string; the interpretation is the same as for integer literals.

Parameters
s
Returns
int(s, 16).

Referenced by main().

◆ int2bin()

def _01d_dec2bin.int2bin (   n,
  count = 24 
)

Converts an integer to a binary string representation with an specified number of bits.

Parameters
nan integer.
countnumber of digits.
Returns
the binary of integer n, using count number of bits.

Referenced by main().

◆ main()

def _01d_dec2bin.main ( )

Variable Documentation

◆ input

_01d_dec2bin.input = raw_input