Python Code Examples For Print Hex

Most Popular Top Python APIs Popular Projects
  • Java
  • Python
  • JavaScript
  • TypeScript
  • C++
  • Scala
  • Blog
Python print hex 18 Python code examples are found related to " print hex". You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. Example 1
Source File: helpers.py From bazarr with GNU General Public License v3.0 6 votes vote down vote up
def print_as_hex(s): """ Print a string as hex bytes. """ print(":".join("{0:x}".format(ord(c)) for c in s)) Example 2
Source File: segments.py From Adafruit_CircuitPython_HT16K33 with MIT License 6 votes vote down vote up
def print_hex(self, value): """Print the value as a hexidecimal string to the display.""" if isinstance(value, int): self.print("{0:X}".format(value)) else: self.print(value) Example 3
Source File: common.py From peach with Mozilla Public License 2.0 5 votes vote down vote up
def printHex(src): FILTER = ''.join([(len(repr(chr(x))) == 3) and chr(x) or '.' for x in range(256)]) N = 0 result = '' length = 16 while src: s, src = src[:length], src[length:] hexa = ' '.join(["%02X" % ord(x) for x in s]) s = s.translate(FILTER) result += "%04X %-*s %s\n" % (N, length * 3, hexa, s) N += length print(result) Example 4
Source File: netbyte.py From netbyte with MIT License 5 votes vote down vote up
def print_hex(string): ''' Print string with hex color configuration ''' print(Fore.BLUE + Style.BRIGHT + string + Style.RESET_ALL) Example 5
Source File: SevenSegment.py From Adafruit_Python_LED_Backpack with MIT License 5 votes vote down vote up
def print_hex(self, value, justify_right=True): """Print a numeric value in hexadecimal. Value should be from 0 to FFFF. """ if value < 0 or value > 0xFFFF: # Ignore out of range values. return self.print_number_str('{0:X}'.format(value), justify_right) Example 6
Source File: __util.py From danmu with MIT License 5 votes vote down vote up
def printHex(buff): count = 0 for c in buff: sys.stdout.write("0X%02X " % ord(c)) count += 1 if count % 16 == 0: sys.stdout.write("\n") sys.stdout.write("\n") sys.stdout.flush() Example 7
Source File: readelf.py From ppci with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def print_hex_dump(elf, section_number): print("Hex dump of section {}:".format(section_number)) data = elf.sections[section_number].data hexdump(data) print() Example 8
Source File: awg_server.py From sds1004x_bode with MIT License 5 votes vote down vote up
def print_as_hex(self, buf): """ Prints a buffer as a set of hexadecimal numbers. Created for debug purposes. """ buf_str = "" for b in buf: buf_str += "0x%X " % ord(b) print buf_str Example 9
Source File: SevenSegment.py From flyover with MIT License 5 votes vote down vote up
def print_hex(self, value, justify_right=True): """Print a numeric value in hexadecimal. Value should be from 0 to FFFF. """ if value < 0 or value > 0xFFFF: # Ignore out of range values. return self.print_number_str('{0:X}'.format(value), justify_right) Example 10
Source File: fwtool.py From fwtool.py with MIT License 5 votes vote down vote up
def printHexDump(data, n=16, indent=0): for i in range(0, len(data), n): line = bytearray(data[i:i+n]) hex = ' '.join('%02x' % c for c in line) text = ''.join(chr(c) if 0x21 <= c <= 0x7e else '.' for c in line) print('%*s%-*s %s' % (indent, '', n*3, hex, text)) Example 11
Source File: sevenSegDisplay.py From Onion-Docs with GNU General Public License v3.0 5 votes vote down vote up
def printHexNumber(self, hexString): hexList = list(hexString) if (hexList[0] is not "0") or (hexList[1] is not "x"): print "Please input a 4-digit hex string beginning with '0x', such as 0x12ab." return -1 hexNum = list(hexString.split("x")[1]) numDigits = len(hexNum) if numDigits > 4: print "Hex number is too long!" return -1 elif numDigits == 0: print "You forgot the number part of the hex string!" return -1 # hex numbers shorter than 4 digits will be printed on the right side blankDigits = 4 - numDigits for i in range(blankDigits): self.setDigit("off", i+1) for i in range(numDigits): character = hexNum[i] if character.isalpha: character = character.lower() if character not in SevenSegDisplay.digitMap: print "Invalid number!" return -1 self.setDigit(character, i + blankDigits) Example 12
Source File: alphanum4.py From fourletter-phat with MIT License 5 votes vote down vote up
def print_hex(self, value, justify_right=True): """Print a numeric value in hexadecimal. Value should be from 0 to FFFF. """ if value < 0 or value > 0xFFFF: # Ignore out of range values. return self.print_str('{0:X}'.format(value), justify_right) Example 13
Source File: example8-decodestr.py From GDA-android-reversing-Tool with Apache License 2.0 5 votes vote down vote up
def printStringHex(stri): ret='' for ch in stri: ret+="%02x " % (ord(ch)) return ret Example 14
Source File: misc.py From pyzatt with MIT License 5 votes vote down vote up
def print_hex(arr): """ Prints a bytearray as a sequence of hex numbers, e.g. "fffe01". :param arr: Bytearray to print. :return: None. """ print(binascii.hexlify(arr)) Example 15
Source File: satel_integra.py From satel_integra with MIT License 5 votes vote down vote up
def print_hex(data): """Debugging method to print out frames in hex.""" hex_msg = "" for c in data: hex_msg += "\\x" + format(c, "02x") _LOGGER.debug(hex_msg) Example 16
Source File: alphanum4.py From rainbow-hat with MIT License 5 votes vote down vote up
def print_hex(self, value, justify_right=True): """Print a numeric value in hexadecimal. Value should be from 0 to FFFF. """ if value < 0 or value > 0xFFFF: # Ignore out of range values. return self.print_str('{0:X}'.format(value), justify_right) Example 17
Source File: print_helper.py From BLESuite with MIT License 4 votes vote down vote up
def print_data_and_hex(data, is_handle_in_data, prefix=""): """Print supplied data followed by the hexadecimal equivalent :param data: List of data strings to be printed or string :param is_handle_in_data: If data supplied contains the source handle sending the data, such as when we read data from a device using a UUID, we need to know to print the handle separate from the handle :param prefix: Prefix all printed lines with the supplied string :type data: list of strings or string :type is_handle_in_data: bool :type prefix: str """ print prefix + "Data (Copy/Paste version)" print prefix + "==========================" if data == -1: print prefix + "Invalid Handle/UUID" print prefix + "=====" return if data == -2: print prefix + "Permission error. Cannot read supplied handle/UUID." print prefix + "=====" return if data is None: print prefix + "No data found from a previous from a previous read operation." print prefix + "=====" return if isinstance(data, list): for i in data: '''chunks = [i[x:x+groupLen] for x in range(0, len(i), groupLen)] for chunk in chunks: print chunk print "-"*(groupLen+1) for chunk in chunks: print " ".join("{:02x}".format(ord(c)) for c in chunk)''' if is_handle_in_data: #UUID read response packets contain #the originating header in the first two bytes #handle reverse order when received handle = i[:2][::-1] i = i[2:] if handle is not None: print prefix + "Handle:", "".join("{:02x}".format(ord(c)) for c in handle) else: print prefix + "Handle:" print prefix + str(i) print prefix + "-" * len(str(i)) print prefix + " ". join("{:02x}".format(ord(c)) for c in str(i)) else: if is_handle_in_data: # UUID read response packets contain # the originating header in the first two bytes # handle reverse order when received handle = data[:2][::-1] i = data[2:] if handle is not None: print prefix + "Handle:", "".join("{:02x}".format(ord(c)) for c in handle) else: print prefix + "Handle:" print prefix + str(data) print prefix + "-" * len(str(data)) print prefix + " ".join("{:02x}".format(ord(c)) for c in str(data)) print prefix + "=====" Example 18
Source File: utils.py From dwc_network_server_emulator with GNU Affero General Public License v3.0 4 votes vote down vote up
def print_hex(data, cols=16, sep=' ', pretty=True): """Print data in hexadecimal. Customizable separator and columns number. Can be pretty printed but takes more time. """ if pretty: print pretty_print_hex(data, cols, sep) else: print sep.join("%02x" % b for b in bytearray(data)) Program Creek

Từ khóa » C 0x 02x