Saturday, March 24, 2012

Python - Converting character string to HEXA string

ord(c): Given a string of length one, return an integer representing the Unicode code point of the character when the argument is a unicode object, or the value of the byte when the argument is an 8-bit string.


hex(n): Convert an integer number to a hexadecimal string


We do not need first to characters in the hex output.


zfill(witdh): Return the numeric string left filled with zeros in a string of length width.


Put of together,


Reference:
href=http://docs.python.org/library/functions.html

Friday, March 23, 2012

Perl - Converting character string to HEXA string



Substitution Operator Modifiers
Here is the list of all modifiers used with substitution operator
Modifier Description
     i   Makes the match case insensitive
     m   Specifies that if the string has newline or carriage
         return characters, the ^ and $ operators will now
         match against a newline boundary, instead of a
         string boundary
     o   Evaluates the expression only once
     s   Allows use of . to match a newline character
     x   Allows you to use white space in the expression
         for clarity
     g   Replaces all occurrences of the found expression
         with the replacement text
     e   Evaluates the replacement as if it were a Perl statement,
         and uses its return value as the replacement text

References:
http://icfun.blogspot.com/2009/05/perl-convert-character-string-into-hex.html
http://www.tutorialspoint.com/perl/perl_regular_expression.htm