modules for handling of hexadecimal data ?

Alex Martelli aleax at aleax.it
Fri May 9 10:01:10 EDT 2003


dr_mabuse wrote:

> ok, next try:
> 
> i am working in the telecommunication business and we develop in a
> language called CHILL which nobody nows, but it doesnt matter.
> now we often get diagnosis outputs in hexadecimal form e.g. 78D00AB6 and
> we know this output has to be interpreted with a structured mode e.g.
> 
> a_structured_mode = struct (similar to c-struct)
> ( component_a    a_mode,
>   componet_b      b_mode,
>   component_c    c_mode);
> 
> each component mode itself may also be a more complex mode and all those
> modes may also have special allignment options and memory layout options
> (LSB-high, LSB-low).
> 
> the tool should now read the hex string and read a database for the
> mode-layout and generate a symbolic output:
> 
> e.g.:
> 
> component_a  = RED,
> component_b = 468750,
> component_c = TRUE
> 
> is it more clear now ?

Reasonably so, except that we have no idea of how that "database
for the mode-layout" is specified.  Does your Python code have to
read and analyze the CHILL declarations to build up said database?
Do you have a database already existing in some format, and if so
do you need to use that [unknown to us] format as it stands, or do
you plan to generate Python code from the database?

The "handling of the hexadecimal data" is the least of it.  You
can transform each pair of hexadecimal digits into a binary byte
(0-255) with int(string_of_two_digits, 16) -- that should, I hope,
make it obvious that the fact that the data are in hex digits
rather than in binary is almost irrelevant.  And from binary and
a description-format for a C-like struct, you can get Python
values with module struct in the standard Python library.  But
that's still only a small part of the way towards the symbolic
structured output you want -- that database had better store the
component-names AND any rules about their output formatting (e.g
that transformation into the string 'RED' exemplified above) as
well as the needed struct format string for each component.


Alex





More information about the Python-list mailing list