Android Question Reading Bytes with Random Access File lib

Discussion in 'Android Questions' started by Aegis, Jan 30, 2015.

  1. Aegis

    Aegis New Member

    Hello, new to the forum and b4a (using it for a trainee work), I'm trying to use the RAF library to read bytes from a stream and turn it into an int (simulated with the dummy) but can't wrap my head around it's output.
    At first i thought my mistake was not adding "" while assigning value to dummy, but even with those i can't uderstand the output (second column in the comments)

    Sub calc
    Dim Dummy(11As Byte
    Dim tmp As Int
    0) = 00000000 'prints 0           0
        Dummy(1) = 11111111 'prints  199           199
        Dummy(2) = 00100000 'prints 0             160
        Dummy(3) = 01000000 'prints 0            64
        Dummy(4) = 10000000 'prints 128         128
        Dummy(5) = 00000001 'prints 1            1
        Dummy(6) = 00000010 'prints 8            10
        Dummy(7) = 00000100 'prints 64           100
        Dummy(8) = 00001000 'prints 0             232
        Dummy(9) = 00010000 'prints 0            16
        Dummy(10) = 01000000 'prints 0           64
        Dim RAF As RandomAccessFile
    For i = 0 To Dummy.Length
    ' should go from 0 to 255

    End Sub
    How does exactly the conversion and assignment work?
    Thanks for your time and help, i'm sure i'll soon feel VERY stupid D:

    PS: Off topic, but how can i get an array or string of 0 and 1 from one of those bytes? I need to manipulate it bit by bit
    Last edited: Jan 30, 2015
  2. Erel

    Erel Administrator Staff Member Licensed User

    Why don't you use RAF.ReadInt? Or use ByteConverter library?
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice