Value from a single byte
Avex
Posts: 4
Maybe i'm overlooking something, but i searched the Netlinx helpfiles and searched this forum, but couldn't find the answer for my 'problem'
From a file i parse a line and in this line is one! character representing an index, this character can be 0-9 and A-Z for calculating i need the value of this character pa. 0=48/ 6=54/A=65/P=80 etc etc
For the numbers i could use ATOI, but for the letters this returns a 0
I can remember from my old ZX81 days that there was something like ASC$(character) even that other brand with the C has a command called byte which returns the value from one byte.
For now i made a stupid lookup table with 36 entrys which do the job, but i'm pretty sure that there must be a more elegant way to do this.
something like this:
Kind Regards
Mark
From a file i parse a line and in this line is one! character representing an index, this character can be 0-9 and A-Z for calculating i need the value of this character pa. 0=48/ 6=54/A=65/P=80 etc etc
For the numbers i could use ATOI, but for the letters this returns a 0
I can remember from my old ZX81 days that there was something like ASC$(character) even that other brand with the C has a command called byte which returns the value from one byte.
For now i made a stupid lookup table with 36 entrys which do the job, but i'm pretty sure that there must be a more elegant way to do this.
something like this:
INTEGER Byte_Value CHAR My_Byte[1] My_Byte = "'A'" Byte_Value = some_command(My_Byte) Byte_Value is now 65
Kind Regards
Mark
0
Comments
char my_byte[] = 'A'
integer my_byteAsDec = 0
my_byteAsDec = my_byte[1]
This will give the my_byteAsDec the value of 65
Tested with both numbers and letters
Is this what you were looking for?
WARNING: \Jingle_PC_control.axi(401): C10570: Converting a string to a [INTEGER]
\Studio_Program.axs - 0 error(s), 1 warning(s)
If it works it should be OK, but can it be done without the warning?
Grtzz Mark
I'm not getting the warning when i convert only 1 char in the string:
my_byteAsDec = my_byte[1] //this is ok. This will only convert the 1 char to integer
my_byteAsDec = my_byte //this will give warning. this tries to convert the whole array.
The [1] behind the byte is what i overlooked, i already did something like :
character = MID_STRING(cLine_Read,24,1) so i presumed this one byte was enough...
Thanks for the answer, it cleared a lot!
Grtzz Mark
That explains my compiler 'nagging' :-) working with different systems with their small but big influence
differences can sometimes be a real pain in the **s
Many thanks for the answers.
Grtzz Mark
Any of the 8 intrinsic data types can be assigned to any other type without the compiler yelling as long as you are not assigning a larger type to a smaller, or assigning a signed type to an unsigned type.
However, you can force NetLinx to ignore this by using TYPE_CAST.
I'm sorry, but what do you mean "if it can be converted at all"? Unless you're including run-time math. Dividing one integer by another may technically result in a floating point value, but the compiler won't catch it since the state of the variables are unknown.
I was just hedging my bets. It may never complain for all I know, but neither have I tried type-casting an elaborate structure to a char, for example.