I'm looking for a simple way in C to convert an string to a byte or binary (8 bit). I'm always going to receive a string between 0 and 255, for example:
- If I receive "0", I want to convert it to 00000000
- If I receive "255", I want to convert it to 11111111
- If I receive "128", I want to convert it to 10000000
This would be useful for me because I'm implementing code in C for a PIC16F1705 where depending on a value I receive via the EUSART module I will put this value in the PWM module to control the power of a DC motor. I'm using the MPLAB IDE and the XC8 compiler in order to be able to use C rather than assembly.