in reply to Looking for ideas: Converting a binary 'flags' field into something human readable

Your ideas?

If 8 bytes is the longest field, I think I'd be tempted to display the binary and annotate only those known fields something like this:

flags1 => 0b010011000010000010100000000010000000000000010100000000 +0000000111; # | compressed # | deleted # | this # | that # | other # | something else # | and another # foo | # bar | # + up | # + down | # s +ideways |

Not pretty, but very clear.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
I'm with torvalds on this Agile (and TDD) debunked I told'em LLVM was the way to go. But did they listen!
  • Comment on Re: Looking for ideas: Converting a binary 'flags' field into something human readable
  • Download Code

Replies are listed 'Best First'.
Re^2: Looking for ideas: Converting a binary 'flags' field into something human readable
by bojinlund (Monsignor) on Jul 08, 2015 at 06:00 UTC

    Or?

    flags1 => 0b010011000010000010100000000010000000000000010100000000 +0000000111; # | || |that | | |and another | |bar + up||| # |this |something else |foo + down| # |deleted | other + sideways| # |compressed

      I'd like to see the code that determines how to compress those together :)


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
      I'm with torvalds on this Agile (and TDD) debunked I told'em LLVM was the way to go. But did they listen!
        Not optimal and missing the "icycles" on the first line, but seems to work:
        لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
        use strict; use warnings; my @labels = ({label=>'compressed',start=>3}, {label=>'deleted',start= +>6}, {label=>'this',start=>7}, {label=>'that',start=>12}, {label=>'other',start=>18}, {label=>'something else',sta +rt=>20}, {label=>'and another',start=>30}, {label=>'foo',start=>4 +5}, {label=>'bar',start=>47}, {label=>'up',start=>63}, {label=>'down',start=>64}, {label=>'sideways',start=>65} +); print "0b0x00xx0000x00000x0x000000000x00000000000000x0x000000000000000 +xxx\n"; my (@lines); # for each label LOOP: foreach my $lab (@labels) { # look thru the available lines foreach my $line (@lines) { my $delta = $lab->{start} - length($line); # for a line shorter than start if ($delta >= 0) { # and tack the label on there $line .= ' ' x $delta . '|' . $lab->{label}; next LOOP; } # or fit into empty space on existing line my $len = length($lab->{label}) + 1; if (substr($line, $lab->{start}, $len) eq ' ' x $len) { substr($line, $lab->{start}, $len,'|' . $lab->{label}); next LOOP; } } # or create a new line if needed push @lines, ' ' x $lab->{start} . '|' . $lab->{label}; } print "$_\n" for @lines;

        UPDATE: added comments, added fitting new label into blank space, improved flow

        Dum Spiro Spero
Re^2: Looking for ideas: Converting a binary 'flags' field into something human readable
by locked_user sundialsvc4 (Abbot) on Jul 09, 2015 at 00:47 UTC

    That seems to me to be a “at least fairly genius” suggestion:   to encode the value as the bit-field which it is, but then to document the meaning of the field to the human reader.   (The computer wouldn’t care.)

    Promptly upvoted.

    The parser-grammar could fairly easily be made to include a descriptor that, one way or another, maps to a (hard-coded) Perl subroutine within the parser ... which generates the comment-entries to describe the field.   (Personally, I think I’d do it as a table, including the starting byte/bit number, the number of bits, and the interpretation.   “ASCII Art” could be unmanageable.)