Created
September 21, 2017 07:34
-
-
Save costastf/3a63389856c43dcfb22d89164aa7a5de to your computer and use it in GitHub Desktop.
String to reverse double word
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
#-*- coding: UTF-8 -*- | |
# File: stringToReverseDoubleWord.py | |
# Copyright (c) 2011 by Costas Tyfoxylos | |
# | |
# GNU General Public Licence (GPL) | |
# | |
# This program is free software; you can redistribute it and/or modify it under | |
# the terms of the GNU General Public License as published by the Free Software | |
# Foundation; either version 2 of the License, or (at your option) any later | |
# version. | |
# This program is distributed in the hope that it will be useful, but WITHOUT | |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | |
# details. | |
# You should have received a copy of the GNU General Public License along with | |
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple | |
# Place, Suite 330, Boston, MA 02111-1307 USA | |
# | |
import sys | |
__author__ = 'Costas Tyfoxylos <costas.tyf@gmail.com>' | |
__docformat__ = 'plaintext' | |
__date__ = '19/05/2011' | |
def to_hex(string): | |
characters = [] | |
for character in string: | |
byte = hex(ord(character)).replace('0x', '') | |
if len(byte) == 1: | |
byte = '0'+byte | |
characters.append(byte) | |
characters.reverse() | |
counter = 0 | |
double_word = '' | |
for byte in characters: | |
double_word += str(byte) | |
counter += 1 | |
if counter == 4: | |
print '0x' + double_word | |
double_word = '' | |
counter = 0 | |
if double_word: | |
double_word = double_word.zfill(8) | |
print '0x' + double_word | |
return True | |
if __name__ == '__main__': | |
text = sys.argv[1] | |
to_hex(text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment