in reply to Re^2: Parsing through instructions
in thread Parsing through instructions
So the key information you need is that you need to use the bit operators to manipulate the bits in each byte to extract the interesting bit fields. In particular use & (bitwise and) and a bit mask to isolate bit fields, and use the bitwise shift operators >> and << to move fields of bits about. For example, to isolate the op code you'd do something like:
use strict; use warnings; my $byte = 0b00100100; my $opCode = ($byte & 0b11100000) >> 5; printf "Opcode is 0x%02X\n", $opCode;
Prints:
Opcode is 0x01
See perlop for details about the various Perl operators.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Parsing through instructions
by DaveMonk (Acolyte) on Apr 08, 2012 at 23:57 UTC | |
by GrandFather (Saint) on Apr 09, 2012 at 00:09 UTC | |
by DaveMonk (Acolyte) on Apr 11, 2012 at 23:53 UTC |