I am new to c and I'm having trouble with something. According to this I can use byte() to convert value x of any type to byte data type. I am trying to convert "0xff" to 255, but using byte() is displaying 40. Is there a build in function I can use or do I have to build something myself? Thank you.
UPDATE:
I was trying to simplify the problem I was facing, but here is a more detailed idea of what I am trying to do. I am trying to parse some JSON data using ArduinoJson. Below you can see a simplified version of my JSON file and my goal is to create a list of bytes for each frame. I'm using JsonArray to extract the frame lists and then copying the JsonArray to a String array using copyArray and then try to convert that to a list of bytes.
JSON file (simplified; real file is pretty big)
{"frames":{"0":["ff","ff","ff","ff"],"1":["0","0","0","0","0"],"2":["ff","ff","ff","ff"],"3":["0","0","0","0","0"]}}
Would be interesting to know where the "0xFF" string originate from. May be there is more straightforward way if the format could be different. (Otherwise yes, strtoul() is the solution)
I think he is trying to convert the value 0xFF to a char.
In this case, you do not need to surround 0xFF in quotes. The 0x part mean that the following thing is in "hexadecimal format", and a value of FF equal to 0b11111111 (with 0b denote the following to be in binary), or 255.
Just do:
//make the syntax look right
char high = 0xFF;
Note the 0xFF is now blue.
however, if you want to convert "0xFF"(which is a string), you need to throw out the "0x" part because it mean nothing. Then you toss "FF" to a hexadecimal converter (mutation of atoi or the like. I've never seen one before)
maybe he think that the correct representation for 0xFF is a string.
But he understand that 0xFF evaluate to 255, so, maybe he put it intentionally as a string.
I am parsing data from a JSON file using ArduinoJson and one of my variables is a list of string lists and I am trying to convert all those strings to bytes which I will be sending to Teensy.
Im actually parsing data from a JSON file using ArduinoJson and was under the impression that I had to use strings in that format.
This is a simplified version of my JSON file and my goal is to create a list of bytes for each frame. I'm using JsonArray to extract the frame lists and then copying the JsonArray to a String array and then try to convert that to a list of bytes.