How to convert binary data to text and text to binary data

I made a sample program showing how to encode a character to UTF8 and how to decode it. The program will use the Web component and the asynchronous extension hence.

UTF8.aia (24.4 KB)

The second method using java script.

convert.aia (3.6 KB)

Hello Patryk

Encode a character to UTF8 from what? App Inventor lives and breaths UTF8, so what would need to be converted to UTF8 that isn't already handled automatically?

A string of data from an external device downloaded to the application via bluetooth. The device sends a long configuration string to the application. There are both text and numeric values in this string. AppInventor only distinguishes between text and numerical data in the bluetooth component. Read / send text and read / send byte. But the device sends it all together. The decoding of everything to a readable form only takes place on the application side. The decoded information is saved in the dictionary as a key and value. The values are stored in hexadecimal form. For example, the word AppInventor is 417070496E76656E746F72. This way, the configuration is also saved to the file as a backup and sent back to the device. Someone once needed such conversion Ascii <=> Number and someone solved it by adding the string ascii to the text variable and wanting to convert ascii to a number, the positions of this character were taken. It is similar here except that not ascii but utf8.

Unless there is some method in appinventor that I don't know about that will convert my data "417070496E76656E746F72" to the word "AppInventor" that will display it in the text field?

This title will probably be more appropriate. The only time appinventor can read binary data as text is the bluetooth component. If we read such data as binary data, it is not possible to convert them into text in appinventor.

The third and final method is extension :smiley: . I got tired but it worked ...

com.extension.ToolsForAI2.aix (6.2 KB)
test_app.aia (6.8 KB)

blocks (56)

Updated on 17-11-2020

Added block for adding leading zeros. It is used to change e.g. '1A' to '00001A'.

com.extension.ToolsForAI2.aix (6.6 KB)
test_app2.aia (7.5 KB)

Dear Patryk! Im not speak english very well. But i try.

Can U help me please?

If i write one textbox Hungary language letters-> ÁÉŰŐÜÓ ect special characters,
And I send datas to excel The typed text will loss special characters.

Example I type inbox: ALMÁS RÉTES
and click save i see in excel: ALMS RTS

My special chars are loss.

how can i encode to utf-8?

Thank U

Thomas :slight_smile:

AppInventor sends the text in UTF8 format. If the program in which you open the file does not support UTF8, maybe you can change the encoding somewhere in the settings?
Which sheet are you sending data to? How do you save them? I would have to test it.

If you are using Microsoft Excel, there is a function to import text from other encoding formats.

Do you use AppInventor to save in a google sheet, then download the sheet from google and open it in MS Excel?

1 Like

Thanx your quick answear! :slight_smile:

This is my app and script and screenrecord video from app.

https://drive.google.com/drive/folders/1vy648VOkogIoZ0ALysADb8rQV9lCtQIZ?usp=sharing

Can u help me please? :S

Send me your aia

i uploaded in googledrive

https://drive.google. com/file/d/1An2Aso7DjfBCKFVTVwf-kX-oIl1o7jMd/view?usp=sharing

So yeah. I tested a bit and found that the Web.POST.text block does not work with non-ASCII characters.

It works and sends country-specific characters:

This doesn't work and sends blank characters instead of country-specific characters:

Maybe I should use a different block for encoding?