ReadBytes(buffer,0,buffer.Length)

schimanski

Well-Known Member
Licensed User
Longtime User
Hello together!

I tried to read a string from a server to bytes, but when I read out the buffer, most of the values are negativ. What can be the reason for that?

B4X:
Dim buffer(100) As Byte
Dim InputStream1 as InputStream


If InputStream1.BytesAvailable > 0 Then
   bufferlength=InputStream1.ReadBytes(buffer,0,buffer.Length)
end if

Thanks or help....
 

schimanski

Well-Known Member
Licensed User
Longtime User
Thanks, Erel!

Is it possible to transform it? I have to change the bytes into a binarystring and read out some informations out of parts of the binarycode. With the signed bytes, the binarystring is useless for me. I think, that BytesToString doesn't works for my application.:confused:
 
Upvote 0

schimanski

Well-Known Member
Licensed User
Longtime User
Hello Erel, need something help!!!!

I have tried several codes to transform the buffer to an unsigned buffer of bytes, but it doen't work...:BangHead:
I think, that I use ReadUnsignedBytes i a wrong context.....

B4X:
Dim buffer(100) As Byte
Dim InputStream1 as InputStream
Dim Transform As RandomAccessFile

Sub Read_from_server
..
  If InputStream1.BytesAvailable > 0 Then
     bufferlength=InputStream1.ReadBytes(buffer,0,buffer.Length)
  end if
..
end sub

Sub Transform_bytes
Transform.Initialize3(buffer,True)
..
  For i=0 To bufferlength               
    buffer(i)=Transform.ReadUnsignedByte(buffer(i),true)
  next
..
end sub


Thanks for help
 
Upvote 0

schimanski

Well-Known Member
Licensed User
Longtime User
Hello Erel!

I only need the integer number apposite to the unsigned byte (0-255). The server from which I get the data sends a string of unsigned bytes. In basic4ppc I transform the byte with DecToBin in a binary code to get the informtions out of the binary string. The informations are always parses of different bytes. For example: To get an information, I have to transform the binary code of bit 4 to 8 from the first byte and bit 1 to 4 from the second byte to a decimalnumber with BinToDec...

I have read the standards: the informations are saved in the ascii-bytes 128-196..
 
Last edited:
Upvote 0

schimanski

Well-Known Member
Licensed User
Longtime User
Hello Klaus!

I have tested it, but the solutions are not correct,every time.

I have now made it how Erel said:

B4X:
dim buffer(100) as byte
dim buffer_int(100) as long

random1.Initialize3(buffer,False)

  For i=0 To buffer.length               
    buffer_int(i)=random1.ReadUnsignedByte(i)
  next

that works....
 
Upvote 0

Similar Threads

Top