Convert Bin to ASCII

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 7.

Moderator: Benj

Post Reply
RoxxorXx
Posts: 14
Joined: Tue Jan 30, 2018 4:31 pm
Been thanked: 1 time
Contact:

Convert Bin to ASCII

Post by RoxxorXx »

Hi, It's me again,
I search an solution to solve my problem. I need to convert somes vars (in byte) to ascii char and put these char into a string; have you a solution to do that ?

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1287
Joined: Sun Oct 05, 2014 3:20 pm
Location: Russia
Has thanked: 384 times
Been thanked: 614 times
Contact:

Re: Convert Bin to ASCII

Post by QMESAR »

Hi,
You can look in the Flow Code wiki for help on such questions.

http://www.matrixtsl.com/wikiv7/index.p ... =Main_Page

If you Tipe in the search String functions you will see a few things that might help you
12.jpg
12.jpg (93.78 KiB) Viewed 11049 times
Then if you Search for Type casting and Number Conversions you will also see some valuable stuff
13.jpg
13.jpg (41.25 KiB) Viewed 11049 times
Hop this helps you

RoxxorXx
Posts: 14
Joined: Tue Jan 30, 2018 4:31 pm
Been thanked: 1 time
Contact:

Re: Convert Bin to ASCII

Post by RoxxorXx »

Hi,
Thanks for the answer but it's not clear for me, can you show me an exemple ?

RoxxorXx
Posts: 14
Joined: Tue Jan 30, 2018 4:31 pm
Been thanked: 1 time
Contact:

Re: Convert Bin to ASCII

Post by RoxxorXx »

I think you are not in the same ideo, i would like to convert for exemple 097 098 to a b

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1287
Joined: Sun Oct 05, 2014 3:20 pm
Location: Russia
Has thanked: 384 times
Been thanked: 614 times
Contact:

Re: Convert Bin to ASCII

Post by QMESAR »

RoxxorXx wrote:I think you are not in the same ideo,
Well I am not sure what you mean by this!
i would like to convert for exemple 097 098 to a b
What you want to do is in the wiki which I gave you the link to any case in basic
the Binary value of 0b01000001 = 65 in decimal in both cases the compiler does not care if you give a bin or a dec number for the compiler it is a number and will automatically covert it with that said 0b01000001 = 65 when you use the ToStr$(number) you will have the A as you see 097 is not A in ASCII ,A is 0x41 in HEX
can you show me an exemple ?
may be you should show us what you want to do ? then people can help you better

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Convert Bin to ASCII

Post by Benj »

Hello,

If you are trying to convert an ASCII string e.g. "097" into a numeric variable then you would do so like this.

Here is some basic pseudocode.

Code: Select all

index = 0
str = "097"
length = Length$(str)
number = 0
while (index < length)
{
 if (str[index] < '0' || str[index] > '9')  //Check next character is numeric
 {
   index = length     //bail out if not
 }
 else
 {
   number = number * 10
   number = number + (str[index] - '0')
   index = index + 1
 }
}
The variable number should now be equal to 97, if you call the LCD function with a PrintASCII then you will get an 'a'.

RoxxorXx
Posts: 14
Joined: Tue Jan 30, 2018 4:31 pm
Been thanked: 1 time
Contact:

Re: Convert Bin to ASCII

Post by RoxxorXx »

Hi, I'm back;
So I don't know i'f i'm understand; I would like to convert a number as an ascii char c: so if I have :

Code: Select all

Int data_number = 97; 
I would like to convert that to

Code: Select all

Char (String) data_string = "h";
so do a sort of

Code: Select all

Char (String) data_string = toAscii(data_number); //convert 97 to "h"
Have you a solution to do that ?

Thanks if you answer :D

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Convert Bin to ASCII

Post by Benj »

Hello,

97 is equal to 'a' they are the same to the processor.

To make 97 equal to 'h' then simply add 7 to the value?

RoxxorXx
Posts: 14
Joined: Tue Jan 30, 2018 4:31 pm
Been thanked: 1 time
Contact:

Re: Convert Bin to ASCII

Post by RoxxorXx »

Oh yes, my bad it's a for 97 but this number is just an exemple.
So Can i convert the number into a char ?

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Convert Bin to ASCII

Post by LeighM »

Hi,
Characters are numbers, the number defines the character that the display device prints.
Have a look at this table
http://www.asciitable.com/

So

Code: Select all

my_string = "hi"
is the same as

Code: Select all

my_string[0] = 104;
my_string[1] = 105;
my_string[2] = 0;
strings end with a 0 (null)

RoxxorXx
Posts: 14
Joined: Tue Jan 30, 2018 4:31 pm
Been thanked: 1 time
Contact:

Re: Convert Bin to ASCII

Post by RoxxorXx »

I'm back and I have à big question : WHY
It's possible to use the ascii extend table ? because i would like encode data between 0 and 255. Have you a solution to do that ?

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Convert Bin to ASCII

Post by Benj »

Hello,
I'm back and I have à big question : WHY
I think your going to have to give us more to go on? WHY what?
It's possible to use the ascii extend table ?
To do what?
because i would like encode data between 0 and 255.
to go into a file? to be sent over a serial connection? to be stored in a program? Can you not just use the numeric values 0 to 255?

RoxxorXx
Posts: 14
Joined: Tue Jan 30, 2018 4:31 pm
Been thanked: 1 time
Contact:

Re: Convert Bin to ASCII

Post by RoxxorXx »

So I have 2 modules one master and one slave. The communication between these module is create with zigbee. I have 6 data to transmit so between the modules its easy but after that I must transmit these data with the serial usb.

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Convert Bin to ASCII

Post by LeighM »

One possible solution would be to send the byte values as a pair of 2 hexadecimal characters,
take the most significant 4 bits (high nibble) and convert to a hexadecimal character,
take the least significant 4 bits (low nibble) and convert to a hexadecimal character.

RoxxorXx
Posts: 14
Joined: Tue Jan 30, 2018 4:31 pm
Been thanked: 1 time
Contact:

Re: Convert Bin to ASCII

Post by RoxxorXx »

Have you an exeple to do that ? How can I check the seperation of the data ? I have a start byte and a end byte but between that if I have a 1 data ?

my data is :

start
U
I
state 1
state 2
id
stop

so it's can be 128,55,78,45,15,25,127, or 128,48,78,245,51,52,127

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Convert Bin to ASCII

Post by LeighM »

Right, now you are starting to give us more of the full picture :)
Does the data at the USB receiving end need to be machine or human readable?
The start (128) and stop (127) values seem to imply that the data bytes can never be those values, is that correct?
If the data is to be human readable you could simply convert the 128 to say a < character and 127 to > character and then use ToString to convert the byte data values to numeric strings, with a comma between. Just one idea. Hence you would see :
<55,78,45,15,25>

RoxxorXx
Posts: 14
Joined: Tue Jan 30, 2018 4:31 pm
Been thanked: 1 time
Contact:

Re: Convert Bin to ASCII

Post by RoxxorXx »

Yes it's a posibility thks c:

Post Reply