7 bits encoding

Nizze

Active Member
Licensed User
Longtime User
Hi .
Are there any "built in" functions to decode a 7 bit's string in B4A ??
Almost the same as in PDU for SMS packege.

// Nizze
 

Nizze

Active Member
Licensed User
Longtime User
Can't you use ASCII encoding for 7 bit strings?

Hi

If i knew how i would ....
Can you give me a hint ??


By the way ..
Yesterday i was playing with buttons on my XOOM .
But if i made a button , "GradientDrawable". ( to have the rounded corners ) and tryed to change the back color in the code then the shape of the button changes ( no round corners ) .
btn1.Color = Colors.red

Or cant i do the color change on a button with "rounded corners" ??

Br

Nizze
 
Upvote 0

Djembefola

Active Member
Licensed User
Longtime User
If i knew how i would ....

You can use ISO 8859-1

for example with the TextReader .Initialize2 Method
or with the BytesToString() Function


B4X:
Dim Reader As TextReader
    Reader.Initialize2(File.OpenInput(File.DirInternal, "test.txt"),"8859-1")
    Dim line As String
    line = Reader.ReadLine
    Do While line <> Null
        Log(line)
        line = Reader.ReadLine
    Loop
    Reader.Close
 
Upvote 0

Nizze

Active Member
Licensed User
Longtime User
Yes

Can you post a file with a string encoded in this format?

Hi

Look at the link that Agraham posted above.
That is almost exactly the same .

I a trying to do a "module" that can decode 7 Bits PDU .

Br

Nizze
 
Last edited:
Upvote 0

Nizze

Active Member
Licensed User
Longtime User
Almost exactly the same is not enough to build and test an algorithm that decodes your format.


It is the the same way of decoding .

If u send in the string containing "E8329BFD4697D9EC37" then
the result is "hellohello".

Thanks for helping out !!

Br

Nizze
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can use this code:
B4X:
Sub process_globals
   Dim GSM_DEFAULT_ALPHABET_TABLE As String
   GSM_DEFAULT_ALPHABET_TABLE = "@£$¥èéùìòÇ" & Chr(10) & "Øø" & Chr(13) & _
      "ÅåΔ_ΦΓΛΩΠΨΣΘΞ*ÆæßÉ !" & QUOTE & "#¤%&'()*+,-./0123456789:;<=>?¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà"
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Dim data() As Byte
   data = Array As Byte(0xE8, 0x32, 0x9B, 0xFD, 0x46, 0x97, 0xD9, 0xEC, 0x37)
   Log(DecodeSeptets(data, 10))
End Sub

Sub DecodeSeptets(Data() As Byte, Length As Int) As String
   Dim res As StringBuilder
   res.Initialize
   Dim i, rest, restBits As Int
   Do While res.Length < Length
      Dim d As Int
      d = Bit.And(0xFF, Data(i))
      i = i + 1
      rest = Bit.Or(rest, Bit.ShiftLeft(d, restBits))
      restBits = restBits + 8
      Do While res.Length < Length AND restBits >= 7
         Dim b As Byte
         b = Bit.And(rest, 0x7F)
         res.Append(GSM_DEFAULT_ALPHABET_TABLE.CharAt(b))
         rest = Bit.UnsignedShiftRight(rest, 7)
         restBits = restbits - 7
      Loop
   Loop
   Return res.ToString
End Sub

It is based on this open source project: SMS library for the Java platform | Download SMS library for the Java platform software for free at SourceForge.net
 
Upvote 0

Nizze

Active Member
Licensed User
Longtime User
Yes

You can use this code:
B4X:
Sub process_globals
   Dim GSM_DEFAULT_ALPHABET_TABLE As String
   GSM_DEFAULT_ALPHABET_TABLE = "@£$¥èéùìòÇ" & Chr(10) & "Øø" & Chr(13) & _
      "ÅåΔ_ΦΓΛΩΠΨΣΘΞ*ÆæßÉ !" & QUOTE & "#¤%&'()*+,-./0123456789:;<=>?¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà"
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Dim data() As Byte
   data = Array As Byte(0xE8, 0x32, 0x9B, 0xFD, 0x46, 0x97, 0xD9, 0xEC, 0x37)
   Log(DecodeSeptets(data, 10))
End Sub

Sub DecodeSeptets(Data() As Byte, Length As Int) As String
   Dim res As StringBuilder
   res.Initialize
   Dim i, rest, restBits As Int
   Do While res.Length < Length
      Dim d As Int
      d = Bit.And(0xFF, Data(i))
      i = i + 1
      rest = Bit.Or(rest, Bit.ShiftLeft(d, restBits))
      restBits = restBits + 8
      Do While res.Length < Length AND restBits >= 7
         Dim b As Byte
         b = Bit.And(rest, 0x7F)
         res.Append(GSM_DEFAULT_ALPHABET_TABLE.CharAt(b))
         rest = Bit.UnsignedShiftRight(rest, 7)
         restBits = restbits - 7
      Loop
   Loop
   Return res.ToString
End Sub

It is based on this open source project: SMS library for the Java platform | Download SMS library for the Java platform software for free at SourceForge.net


Hi .

Thanks ! !

That did the thing !!

// Nizze
 
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
Bit Encoding

I'm trying to take the length of a string and convert it into two bytes within a byte array.
For example: the string length is 423 bytes; I need to convert the length into a byte array of 2 bytes; This byte array will be transmitted via TCP to a PC program that will decode these bytes into an integer using bitconverter.toUIint16

I understand and can decode the bytes upon arrival, but am needing advice on what methods are used within B4a that will convert the length into the byte array.
Any advice/help will be appreciated.
Thanks in advance
 
Upvote 0
Top