Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Could someone please help in converting this Perl code to .Net?

PERL
sub xor16 {
local(@x) = @_[0..15];
local(@y) = @_[16..31];
local(@results16) = ();
for($j=0;$j<16;$j++)  {
if (shift(@x) eq shift(@y)) { push(@results16, '0'); }
else { push(@results16, '1'); }
}
return(@results16[0..15]);
}
{
local($st_data) = $ARGV[0];
local(@G) =
('1','0','0','0','0','0','0','0','0','0','0','0','0','1','0','1');
local(@hold) =
('1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1');
local(@data) = split (//,$st_data);
if (scalar(@data) > 0)  {
loop16: while (scalar(@data) > 0)  {
$nextb=shift(@data);
if (($nextb ne "0") && ($nextb ne "1")) {next loop16} ## comment
character
if ($nextb eq shift(@hold)) {push(@hold, '0')}
else  { push(@hold, '0'); @hold = &xor16(@hold,@G); }
}
}
# print (@hold); print "\n";
## invert shift reg to generate CRC field
for ($i=0;$i<=$#hold;$i++) {if (@hold[$i] eq "1") {print("0")} else {
print("1")} }
print "\n";
}
Posted
v2

Nobody can do this for you.
If you know both the languages, then you will be able to convert it.

First try to understand the logic which is implemented and then try to convert it to the equivalent code in .NET.

If you can't understand the logic, then try to learn Perl first or take help from a Perl guy (may be your friend or colleague).

Here we deal with specific questions and issues. So, come with a specific issue next time.

Thanks,
Tadit
 
Share this answer
 
Assumin you know what the Perl program achieves and assuming you have a suitable test suite to verify that functionality, then you may start as described below:
1) Be aware: Perl has only a weak type system. C# has a far mor strict type system.
2) So, first find out what the values represent in Perl and what types they would be in C#.
3) Then think of what data structures you would use in C# instead of the ones in Perl (e.g. arrays of XXX, etc.).
4) write the same functions as available in Perl in C# (Xor16 and Main).
5) run you test suite on the converted program and fix bugs.
6) Have fun!
Cheers
Andi
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900