#!/usr/bin/perl
use warnings;
use strict;

my $filename = shift || die;

open(FH, "$filename");

while(<FH>)
{
	# Get all the data adress:
	$_ =~ /(\d+):\s+(\w+)\s+0x([\w\d]+)/;
	my $time = $1;
	my $command = $2;
	my $address = $3;
	my $new_address; 

	# Convert to binary:
	$address = sprintf( "%032b", hex( $address ) );
	
	# example:
	# 31                             0
	# 00000000000000000000000000000001
	# 00000000000000000000010000000000

	# Swap adresses:
	$new_address = 	substr($address,31 - 31,1). # R  31
			substr($address,31 - 30,1). # R  30
			substr($address,31 - 29,1). # R  29
			substr($address,31 - 28,1). # R  28
			substr($address,31 - 27,1). # R  27
			substr($address,31 - 26,1). # R  26
			substr($address,31 - 25,1). # R  25
			substr($address,31 - 24,1). # R  24
			substr($address,31 - 23,1). # R  23
			substr($address,31 - 22,1). # R  22
			substr($address,31 - 21,1). # R  21
			substr($address,31 - 20,1). # R  20
			substr($address,31 - 19,1). # R  19
			substr($address,31 - 18,1). # R  18
			substr($address,31 - 17,1). # R  17
			substr($address,31 - 16,1). # R  16
			substr($address,31 -  8,1). # R  15
			substr($address,31 -  7,1). # R  14
			substr($address,31 -  6,1). # R  13
			substr($address,31 - 11,1). # B  12
			substr($address,31 -  9,1). # B  11
			substr($address,31 -  0,1). # B  10
			substr($address,31 - 15,1). # C   9
			substr($address,31 - 14,1). # C   8 
			substr($address,31 - 13,1). # C   7
			substr($address,31 - 12,1). # C   6
			substr($address,31 - 10,1). # C   5
			substr($address,31 -  5,1). # C   4 
			substr($address,31 -  4,1). # C   3
			substr($address,31 -  3,1). # C   2
			substr($address,31 -  2,1). # C   1
			substr($address,31 -  1,1); # C   0
			
	$new_address = sprintf("%X", oct( "0b$new_address" ) );

	print $time.":\t".$command."\t0x".$new_address."\n";
}

