How to turn this simple 10 digit hex number back into 8 digits?

Posted by Babil on Stack Overflow See other posts from Stack Overflow or by Babil
Published on 2011-01-16T11:18:38Z Indexed on 2011/01/16 11:53 UTC
Read the original article Hit count: 184

Filed under:
|
|
|

The algorithm to convert input 8 digit hex number into 10 digit are following:

Given that the 8 digit number is: '12 34 56 78'

x1 = 1 * 16^8 * 2^3
x2 = 2 * 16^7 * 2^2
x3 = 3 * 16^6 * 2^1
x4 = 4 * 16^4 * 2^4
x5 = 5 * 16^3 * 2^3
x6 = 6 * 16^2 * 2^2
x7 = 7 * 16^1 * 2^1
x8 = 8 * 16^0 * 2^0

Final 10 digit hex is:
=> x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 
=> '08 86 42 98 E8'

The problem is - how to go back to 8 digit hex from a given 10 digit hex (for example: 08 86 42 98 E8 to 12 34 56 78)

Some sample input and output are following:

input                output

11 11 11 11          08 42 10 84 21
22 22 33 33          10 84 21 8C 63
AB CD 12 34          52 D8 D0 88 64
45 78 96 32          21 4E 84 98 62
FF FF FF FF          7B DE F7 BD EF

© Stack Overflow or respective owner

Related posts about python

Related posts about algorithm