B4J Question 2's complement

micro

Well-Known Member
Licensed User
Longtime User
Hi to all
where I'm wrong?

This is the code correct in Basic4ppc that work
B4X:
str = Chr(Main.btw.Complement(serbuff(y+i)) + 256)
Where btw is Bitwise library

This in B4j, but not work
B4X:
str = Chr(Bit.Not(serbuff(y+i)) + 256)

I have add 1 to Bit.Not(serbuff(y+i) ?
Thanks
 

micro

Well-Known Member
Licensed User
Longtime User
Please give an example of the input and the expected output.
This is the code on Basic4ppc that work fine:
binprint is Binaryfile
btw is Bitwise
buffer_st is global string variable
serbuff is global array byte (8192)
B4X:
Sub Prepara
Dim larg, lung, fill, padding, length, i, y, centro As Number
Dim mom, mom2
    centro = 0
    If FileExist("/Int/Img/Img1.bmp") Then
            FileOpen(l1, "/Int/Img/Img1.bmp", cRandom)
    Else
        Return
    End If
    binprint.New1(l1, True)
    length = binprint.ReadBytes(serbuff(), 8192)
    FileClose(l1)
    ''''''''preparazione buffer grafico
    larg = ((serbuff(19) * 256 ) + serbuff(18)) /8
    fill = larg Mod 4
    For i = 62 To length - 1
        For y = 0 To larg - 1
            mom2 = Chr(main.btw.Complement(serbuff(y+i)) + 256)
            mom = mom & mom2
        Next y
        '''''''''''''segue correzzione per divisibilità per 4
        If fill > 0 Then i = i + fill
        '''''''''''''''''''''''''''''''''''''''''''''''''''''
        i = i + (larg - 1)
    Next i
    larg = larg + centro
    '''''''''''''''''''''''''''''''''''''''''''''''''''''
    lung = serbuff(22)
    buffer_st = buffer_st & Chr(29) & Chr(118) & Chr(48) & Chr(51) & Chr(larg) & Chr(0) & Chr(lung) & Chr(0) & mom & Chr(10)
End Sub

This is the code modified for B4j:
B4X:
Sub Prepara
Dim larg, lung, fill, padding, length, i, y, centro As Int
Dim mom, mom2 As String
    centro = 0
    If File.Exists(Main.Workingfolder, "Img1.bmp") Then
        Dim instream As InputStream = File.OpenInput(Main.Workingfolder, "Img1.bmp")
    Else
        Return
    End If
    length = instream.BytesAvailable
    Dim BufferImg(length) As Byte
    instream.ReadBytes(BufferImg, 0, instream.BytesAvailable)
    ''''''''preparazione buffer grafico
    larg = ((Bit.And(255, BufferImg(19)) * 256 ) + Bit.And(255,BufferImg(18))) /8
    fill = larg Mod 4
    For i = 62 To length - 1
        For y = 0 To larg - 1
            mom2 = Chr(Bit.Not(BufferImg(y+i)) + 256)
            mom = mom & mom2
        Next
        '''''''''''''segue correzzione per divisibilità per 4
        If fill > 0 Then i = i + fill
        '''''''''''''''''''''''''''''''''''''''''''''''''''''
        i = i + (larg - 1)
    Next
    larg = larg + centro
    '''''''''''''''''''''''''''''''''''''''''''''''''''''
     lung = Bit.And(255, BufferImg(22))
     buffer_st.Append(Chr(29) & Chr(118) & Chr(48) & Chr(51) & Chr(larg) & Chr(0) & Chr(lung) & Chr(0) & mom & Chr(10)
End Sub

The output is on the serial printer.
With Basic4ppc code printing is ok but not with B4j code.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…