#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2009
    Posts
    11
    Rep Power
    0

    Print two Byte number in hex


    Hi,

    I have a counter that counts the contents of an array and displays it like:
    Code:
    for i in status_arr:
              cnt += 1
              statusstr += chr(i)
              logger("["+hexlify(chr(cnt))+"] " + hexlify(chr(i)))
    But this won't work if there's more than 255 elements in the array. How do I display the hex index asa two Byte number?
    Do I do it best like this:
    Code:
    for i in status_arr:
              cnt += 1
              statusstr += chr(i)
              logger("["+hexlify(chr(cnt/256))+hexlify(chr(cnt%256))+"] " + hexlify(chr(i)))
    or are there any other smart ways? Thanks!
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,841
    Rep Power
    480
    Code:
    >>> '%x'%452442898239823
    '19b7e923b114f'
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo