Convert Bin to ASCII
Moderator: Benj
Convert Bin to ASCII
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 ?
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 ?
- QMESAR
- 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
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
Then if you Search for Type casting and Number Conversions you will also see some valuable stuff
Hop this helps you
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
Then if you Search for Type casting and Number Conversions you will also see some valuable stuff
Hop this helps you
https://www.flowcodexchange.com/
Regards QMESAR
Regards QMESAR
Re: Convert Bin to ASCII
Hi,
Thanks for the answer but it's not clear for me, can you show me an exemple ?
Thanks for the answer but it's not clear for me, can you show me an exemple ?
Re: Convert Bin to ASCII
I think you are not in the same ideo, i would like to convert for exemple 097 098 to a b
- QMESAR
- 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
Well I am not sure what you mean by this!RoxxorXx wrote:I think you are not in the same ideo,
What you want to do is in the wiki which I gave you the link to any case in basici would like to convert for exemple 097 098 to a b
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
may be you should show us what you want to do ? then people can help you bettercan you show me an exemple ?
https://www.flowcodexchange.com/
Regards QMESAR
Regards QMESAR
- 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
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.
The variable number should now be equal to 97, if you call the LCD function with a PrintASCII then you will get an 'a'.
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
}
}
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: Convert Bin to ASCII
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 :
I would like to convert that to
so do a sort of
Have you a solution to do that ?
Thanks if you answer
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;
Code: Select all
Char (String) data_string = "h";
Code: Select all
Char (String) data_string = toAscii(data_number); //convert 97 to "h"
Thanks if you answer
- 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
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?
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?
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: Convert Bin to ASCII
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 ?
So Can i convert the number into a char ?
- 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
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
is the same as
strings end with a 0 (null)
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"
Code: Select all
my_string[0] = 104;
my_string[1] = 105;
my_string[2] = 0;
Re: Convert Bin to ASCII
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 ?
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 ?
- 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
Hello,
I think your going to have to give us more to go on? WHY what?I'm back and I have à big question : WHY
To do what?It's possible to use the ascii extend table ?
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?because i would like encode data between 0 and 255.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: Convert Bin to ASCII
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.
- 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
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.
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.
Re: Convert Bin to ASCII
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
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
- 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
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>
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>