C
Chris Richmond - MD6-FDC ~
Folks,
This is a trivial example of a larger problem I'm trying to
speed up. What I want to know is if there is a faster way
to impliment a shift register for text chars. I already tried
using arrays and unshifting and popping, and it was 2-3x slower.
Thx, Chris
Output:
-> 0000 -> (pre-shifting)
1 -> 1000 -> 0
1 -> 1100 -> 0
1 -> 1110 -> 0
0 -> 0111 -> 0
1 -> 1011 -> 1
1 -> 1101 -> 1
1 -> 1110 -> 1
0 -> 0111 -> 0
0 -> 0011 -> 1
0 -> 0001 -> 1
1 -> 1000 -> 1
0 -> 0100 -> 0
1 -> 1010 -> 0
0 -> 0101 -> 0
1 -> 1010 -> 1
1 -> 1101 -> 0
1 -> 1110 -> 1
1 -> 1111 -> 0
0 -> 0111 -> 1
0 -> 0011 -> 1
0 -> 0001 -> 1
0 -> 0000 -> 1
Script:
#!/usr/bin/perl -w
$shift_register = '0000';
$input_data = ' ';
$output_data = ' ';
print " $input_data -> $shift_register -> $output_data (pre-shifting)\n";
while(defined($input_data=(<DATA>))) {
chomp($input_data);
$shift_register = $input_data . $shift_register; # prepending $input_data char
$output_data = chop( $shift_register ); # shifting off the last char to $output_data
print " $input_data -> $shift_register -> $output_data\n";
}
__DATA__
1
1
1
0
1
1
1
0
0
0
1
0
1
0
1
1
1
1
0
0
0
0
This is a trivial example of a larger problem I'm trying to
speed up. What I want to know is if there is a faster way
to impliment a shift register for text chars. I already tried
using arrays and unshifting and popping, and it was 2-3x slower.
Thx, Chris
Output:
-> 0000 -> (pre-shifting)
1 -> 1000 -> 0
1 -> 1100 -> 0
1 -> 1110 -> 0
0 -> 0111 -> 0
1 -> 1011 -> 1
1 -> 1101 -> 1
1 -> 1110 -> 1
0 -> 0111 -> 0
0 -> 0011 -> 1
0 -> 0001 -> 1
1 -> 1000 -> 1
0 -> 0100 -> 0
1 -> 1010 -> 0
0 -> 0101 -> 0
1 -> 1010 -> 1
1 -> 1101 -> 0
1 -> 1110 -> 1
1 -> 1111 -> 0
0 -> 0111 -> 1
0 -> 0011 -> 1
0 -> 0001 -> 1
0 -> 0000 -> 1
Script:
#!/usr/bin/perl -w
$shift_register = '0000';
$input_data = ' ';
$output_data = ' ';
print " $input_data -> $shift_register -> $output_data (pre-shifting)\n";
while(defined($input_data=(<DATA>))) {
chomp($input_data);
$shift_register = $input_data . $shift_register; # prepending $input_data char
$output_data = chop( $shift_register ); # shifting off the last char to $output_data
print " $input_data -> $shift_register -> $output_data\n";
}
__DATA__
1
1
1
0
1
1
1
0
0
0
1
0
1
0
1
1
1
1
0
0
0
0