Well first consider that 1..359 (or is that 0-359?) takes 9 bits (or practically speaking, 2 bytes = 16 bits). How much precision do you need? If you represent that in 0..255 you can fit it in one byte and work with it more easily, at a cost of making each degree 'bigger' and losing some accuracy. Or if your working range is smaller (say you only want to work in the 51-173 range) you might want to do part of the comparison in ASCII (reject leading 3, or 2 hundred) and then convert to binary (fitting in 8 bit) and work from there.
However, the general answer to your question is:
AZ = 0 for each ASCII byte: AZ = AZ * 10 AZ = AZ + byte - "0" ; that's the ASCII value of 0, MPASM ; uses quotes for that, C would use ''
If you are really getting 000 .. 359 (ie always 3 digits) you can do
AZ = 100 * (first ASCII byte - "0") AZ = AZ + 10 * (second ASCII byte - "0") AZ = AZ + third ASCII byte - "0"
If you want to convert and scale at the same time, 256/360=.71111:
AZ = 71 * (first - "0") AZ = AZ + 7 * (second - "0") AZ = AZ + (third - "0") * 3 / 4 ; that's easier pic math than *7/10 AZ = AZ + 1 ; biases better
That's off by at most 1 degree everywhere, which is better than I expected with the *3/4 trick.
ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here.
All logos and trade names are the property of their respective owners.