1

I am trying to convert a java code to Swift. I am using a lib CryptoSwift. This the java code

if(mcrc==0)
{
    Checksum checksum = new CRC32();
    checksum.update(pDataResult, 0, iDest);
    long checksumValue = checksum.getValue();
    mcrc=1;
    liCrc32=(int)checksumValue;
    }

if (this.mbTxCrc16)
{
    bData = (byte)(lcCrc16 >>> bContCrc * 8 & '\u00ff');
}
else
{
    bData = (byte)(liCrc32 >>> bContCrc * 8 & 0xFF);
}
++bContCrc;

My progress in swift. I am stucked

if(mcrc==0)
{
    let data  = NSData.withBytes([0x01,0x02,0x03])
    let crc = data.crc32()
    let checksumValue  =  crc?.checksum().value
    mcrc=1
    liCrc32 = Int(checksumValue)
}
if let a = mbRxCrc16 as? Bool 
{
    if a == true
    {
        bData = UInt8(Int16(lcCrc16) >> Int16(8 * bContCrc) & 0x00FF)
    }
    else
    {
        bData = UInt8(Int32(liCrc32) >> Int32(8 * bContCrc) & 0xFF)
    }
}
else
{
    bData = UInt8(Int32(liCrc32) >> Int32(8 * bContCrc) & 0xFF)
}

all help will be appriciate

bolo

jww
  • 97,681
  • 90
  • 411
  • 885
Bolo
  • 2,668
  • 4
  • 27
  • 34

0 Answers0