Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Sun Sep 22, 2019 10:22 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Porting a litle routine
PostPosted: Wed Mar 16, 2011 3:58 am 
Offline

Joined: Wed Mar 16, 2011 2:23 am
Posts: 2
Hi,

I'm very new to realbasic. Just bought my lisence yesterday.
However now I'm stock into a problem.
I have to port a litlte routine to realbasic.
I have a perl, javascript and Vb version.

Maybe someone can help. I don't understand that byteshifting stuff.

Javascript code:
Number.prototype.unsign = function(bytes) {
return this >= 0 ? this : Math.pow(256, bytes || 4) + this;
};

function FindCRC(data) {
var CRC=0xffffffff;
data = data.toLowerCase();
for (var j=0; j<data.length; j++) {
var c = data.charCodeAt(j);
CRC ^= c << 24;
for(var i = 0; i<8; i++) {
if(CRC.unsign(8) & 0x80000000) {
CRC = (CRC << 1) ^ 0x04C11DB7;
} else{
CRC <<= 1;
}
}
}
if ( CRC < 0 ) CRC = CRC>>>0;
return CRC.toString(16);
}
alert(FindCRC("Hello World"));

Perl code:
my $dataToHash = "Hello World";
my $tmpstr = sprintf "%08x.tbn\n", xbmcHash($dataToHash);
print substr($tmpstr,length($tmpstr)-13,13);

sub findcrc {

my( $hashInput ) = shift;
$hashInput = lc $hashInput;
my $m_crc = 0xFFFFFFFF;

for my $byte( unpack 'C*', $hashInput ) {
$m_crc = $m_crc ^ ( $byte << 24 );
for (my $rep = 0; $rep < 8; $rep++) {
if (( $m_crc & 0x80000000) == 0x80000000) {
$m_crc = ($m_crc << 1) ^ 0x04C11DB7;
} else {
$m_crc = ($m_crc << 1);
}
}
}
return $m_crc;
}

and an untestet vbcode
Public Function FindCrc(ByVal input As String) As String
Dim chars As Char() = input.ToCharArray()
Dim index As Integer = 0
While index < chars.Length
If Convert.ToSByte(chars(index)) <= 127 Then
chars(index) = System.[Char].ToLowerInvariant(chars(index))
End If
System.Math.Max(System.Threading.Interlocked.Increment(index), index - 1)
End While
input = New String(chars)
Dim m_crc As UInteger = 4294967295
Dim bytes As Byte() = System.Text.Encoding.UTF8.GetBytes(input)
For Each myByte As Byte In bytes
m_crc = m_crc Xor (System.Convert.ToUInt32(myByte) << 24)
Dim i As Integer = 0
While i < 8
If (System.Convert.ToUInt32(m_crc) And System.Convert.ToUInt32(2147483648)) = (2147483648) Then
m_crc = (m_crc << 1) Xor System.Convert.ToUInt32(&H4C11DB7)
Else
m_crc <<= 1
End If
System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1)
End While
Next
Return [String].Format("{0:x8}", m_crc)
End Function

Thank you very much


Top
 Profile  
Reply with quote  
 Post subject: Re: Porting a litle routine
PostPosted: Tue Apr 12, 2011 2:29 pm 
Offline

Joined: Wed Mar 16, 2011 2:23 am
Posts: 2
hm, thats hard :shock:
Lets make this litle bit more intersting.
I would pay 100,-EUR for the solution.


Top
 Profile  
Reply with quote  
 Post subject: Re: Porting a litle routine
PostPosted: Sun Jun 05, 2011 7:56 am 
Offline

Joined: Sun Mar 26, 2006 11:02 am
Posts: 85
Did you ever get this converted?

There are lots of free CRC calculator routines around, some more convoluted than others. The one I like uses a lookup table which makes the code much simpler. If interested, I could post it.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group