Decimal Number To Byte(s) And String To Byte(s) Converter

Category: Python - Miscellaneous

A function to convert decimal integer numbers, (from 0 to 255), into byte(s) format.
Another function calling the above function to convert ASCII strings into byte(s) format.

Python 3.1.3 (r313:86834, Nov 28 2010, 10:01:07)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.

>>> exec(open('/home/G0LCU/Desktop/Code/d2b.py').read())
>>> a=78
>>> type(a)
<class 'int'>
>>> b=d2b(a)
>>> print(b)
b'N'
>>> type(b)
<class 'bytes'>
>>> text="x00(C)2012, B.Walker, G0LCU.xFF"
>>> len(text)
27
>>> type(text)
<class 'str'>
>>> newtext=t2b(text)
>>> len(newtext)
27
>>> print(newtext)
b'x00(C)2012, B.Walker, G0LCU.xff'
>>> type(newtext)
<class 'bytes'>


It requires NOTHING special at all to work and can be run like above or imported from
the correct "Lib" drawer/folder/directorfy as:-

>>> import d2b


And when imported called as:-

>>> d2b.d2b(some_number, optional_some_other_mumber)<RETURN/ENTER>


OR

>>> d2b.t2b(some_ASCII_string)<RETURN/ENTER>


Read the code for much more information...

Issued under the GPL2 licence.

Enjoy finding simple solutions to often very difficult problems.

Bazza, G0LCU. Date: 05 January, 2012


Bytes - Converter - Decimal - Linux - String - Windows

Homepage: http://code.activestate.com/recipes/578025-decimal-number-to-bytes-and-string-to-bytes-conver/?in=lang-python

Developer: Barry Walker

License: Freeware

Operating System: Windows

Add a Comment

all are required fields

     
What do you think of this resource?

Select Your Rate:

Votes:0

 

Related Scripts Download

The NumericalChameleon is a free platform independent 100% Pure-Java-Application.

developer Developer: Johann Loefflmann
license License: Freeware
operating systems Operating System: Linux, Unix, Windows


This program will convert *bits to *Bytes.

developer Developer: planet-source-code.com
license License: Freeware
operating systems Operating System: All


Here goes.

developer Developer: Giampaolo Rodol?
license License: Freeware
operating systems Operating System: Windows


Convert an integer number of bytes to a string representation.

developer Developer: Doug Latornell
license License: Freeware
operating systems Operating System: Windows


This is a simple Bitset type for Python.

developer Developer: geremy condra
license License: Freeware
operating systems Operating System: Windows


neo_my2pg is a Python script for migration from mysql to postgresql.

developer Developer: SourceForge.net
license License: Artistic License, GNU General Public License (GPL)
operating systems Operating System: Windows, Linux, Mac OS, BSD, Solaris


Perl Audio Converter (PAC) is a tool for converting multiple audio types from one format to another.

developer Developer: Philip Lyons
license License: GNU General Public License (GPL)
operating systems Operating System: Linux


This method uses inverse IFS transformations and it does not use a random number generator.

developer Developer: FB36
license License: Freeware
operating systems Operating System: Windows


This is not for the big guns, but for the Amateur coder AND radio enthusiast.

developer Developer: Barry Walker
license License: Freeware
operating systems Operating System: Windows