How do you Convert Binary to Text in MIT App Inventor?

Hello everyone,

First of all, I want to thank the community for the previous help I received in implementing the decoding part of my project. Thanks to that, the decoding process is now working perfectly.

Now, I need assistance with a different part of the project. I am trying to format a binary string so that every 8 bits are grouped and separated by a space.

Explanation: Given a binString of length n (at the final project, it will recieve sequences of bits every time it is working), I want to:

  1. Insert a space every 8 bits to keep the structure intact.
  2. Ensure that no segmentation errors occur.
  3. Handle cases where the string length is not a multiple of 8.

:small_blue_diamond: What I Need Help With

Sequence received
"111111110100110101100001011100110110100101101110110011"

Sequence expected
"11111111 01001101 01100001 01110011 01101001 01101110 110011"

What I received
"111111 10100110 1011000010110000 10111001 001101"

  • Making sure the script correctly groups exactly 8 bits per block.
  • Preventing out-of-range errors when the length is not a multiple of 8.
  • Ensuring the final result is correctly formatted.

I appreciate any help! Thank you in advance! :blush:

The project I'm working with:
binaryToText2.aia (4.9 KB)

How it should works:

  1. binString = "01111111 10100110 10110000 10111001 00110100 10110111"

  2. binString = "011111111 10100110 10110000 10111001 00110100 101101111"

  3. binString = "11111111 10100110 10110000 10111001 00110100 10110111"

  4. binStringList = ["11111111", "10100110", "10110000", "10111001", "00110100", "10110111"]

Try this ?

image

Draggable blocks

could you send me the .aia please

If you click on the blocks above to make them full size, you can drag them onto your project.

If you like recursion:

image

2 Likes

thanks both of you for the reply, i'll try and i'll tell you later

Title: Help Needed – Bit Shifting Not Working as Expected in Loop

Hello everyone,

Thanks again for the help I previously received — the decoding part of my project works perfectly. Now, I’ve run into a new issue.

:small_blue_diamond: What I'm Trying to Do:

I want to create a system that continuously shifts a binary string by:

  1. Removing the first bit (from the left),
  2. Adding a new bit to the end (on the right),
  3. Keeping the string structured in 8-bit blocks separated by spaces,
  4. Repeating this process automatically in a loop, not manually.

Currently, I'm using a button to do this bit-shifting step-by-step, but the behavior becomes unpredictable after the first few presses — it works for one iteration, then starts failing or giving inconsistent formatting. In all iterations, the decoding returns "not found", even when the right sequence is supposed to be there.


:small_blue_diamond: My Current Situation:

Here’s an example of what’s happening step-by-step after each button press:

Expected decoding target: 
00000000 00000011 11111101 00100001 00111101 00110001

Bit-shift progression:
1) 000000   00000011 1111110 1 001000 01 00111 101 0011
2) 00000   00000011 111111 0 1 0010 00 01 00 111 101
3) 0000   00000011 11111 1 0 1 00 10 00 01 00 11
4) 000   00000011 1111 1 1 0 1 00 10 00 01
5) 00   00000011 111 1 1 1 0 1 00 10 00
6) 0   00000011 11 1 1 1 1 0 1 00 10
7)     00000011 1 1 1 1 1 1 0 1 0
8)      00000011 1 1 1 1 1 1 0 1
9)       00000011 1 1 1 1 1 1
10)        00000011   1 1 1 1 1
11)        00000011   1 1 1 1
12)        00000011   1 1 1
13)         00000011   1
14)         00000011

Despite the correct sequence being in the string, the decoder fails to find it, returning "not found" every time.


:small_blue_diamond: What I'm Asking For Help With:

  • How can I reliably implement a bit-shift mechanism in MIT App Inventor, where:

    • The first bit is removed,
    • A new bit is added to the end,
    • The string is reformatted every time into 8-bit blocks with spaces,
    • The loop works continuously or smoothly (not just per button press)?
  • How can I avoid the formatting errors that cause the decoder to miss the actual data?

I’m attaching the blocks I’m using for this logic, and would really appreciate any suggestions to improve the implementation or restructure the logic better for this bit-shifting system.

Thanks a lot in advance! :pray:

This is the actual code:
binaryToText4.aia (4.6 KB)

Not clear (to me) what it is you want to do...

If, for example, you start from here:

00000000 00000011 11111101 00100001 00111101 00110001

What would the first/second/third... iteration look like ?

Original:
00000000 00000011 11111101 00100001 00111101 00110001

1st shift:
0000000 00000111 11111010 01000010 01111010 0110001

2nd shift:
000000 00001111 11110100 10000100 11110100 110001

3rd shift:
00000 00011111 11101001 00001001 11101001 10001

4th shift:
0000 00111111 11010010 00010011 11010011 0001

5th shift:
000 01111111 10100100 00100111 10100110 001

6th shift:
00 11111111 01001000 01001111 01001100 01

7th shift:
0 11111110 10010000 10011110 10011000 1

8th shift:
11111101 00100001 00111101 00110001

And so on...

How do you know if the new bit on the right should be a one vs a zero?

No no no, it's more easy. We are just deleting the first number on the left and we are shifting every bit one position to the left keeping the 8 bits size

The main thing is that I've tried the program you uploaded and it works, but at the moment I'm combining with the decoding (bin->text) it works unusually and here is the problem I'm facing

I do not understand how you maintain the 8 bits if your string is only, for example, 4 :

0100 <<should need 4 0's here ?

Remember we are only working with text...

Take the eightified text and save it in a Label.Text

Then in your repeating Clock Timer, set the Label.Text to left_shift(Label.Text).

The idea is that you won't get less than 8 bits because you will get a new bit for the bit you lost. You are always maintaining the same amount of bit. Eg: [1] <- [0101010] <-[1]

Thank you so much for your response. Although, the problem is my code (just few answers above). When trying to use the sequence that is shifting the bits when deleting one of them, the program should decode the sequence into normal text, and it's not working. I tried both parts separately and it works, but joint not. That's the issue.

Are you doing the kind of decoding that requires an ASCII table?

Exactly! The program itself tries to receive a binary sequence constantly and when it receives the header, the program starts to decide with an ASCII table the message that follows the header (i also thought about using a some bits to show the size of the message to determine when we start to finish the decoding and start again waiting for a new header

You mentioned that you were using a header of '11111111' (8 1's) to mark the start of the text.

Your binString text block starts with 14 0's before the 8 bit header.

So I am guessing you are watching some bit stream but came in in the middle of transmission, and don't have access to any byte delimitting markers that you would get in serial traffic, where the front edge of a byte is stretched out in time?

In that case, you could use the text block that searches for the index in a longer text (binString) of a given short piece of text ('11111111'). Once you have that non-zero index, you can use that to clip off the header and the pre-header, leaving only the stuff past the header.
(Same logic as my left shift, but use the index+7 instead of 1.)

Then take the remainder and eightify it, split at spaces, and do the lookups of the list items in your incomplete ascii table, using '?' as a not found value to keep output neat and aligned right.