Need to concatenate a string, #1+#2+#3=#123. Help!
laser-vector
Posts: 118
[EDIT] i changed the title of this thread just because i didnt feel starting a new one was necessary. original title was: "Need a way to take 4 numarical ASCII chars and convert to a real number" the new issue im having is that i need to take and array of bytes
eg. Byte Variable[2]
Variable[0] = 1
Variable[1] = 2
Variable[2] = 3
and concatenate them into one Long so that the long equals the actual number #123
[original thread]
lets say im using a terminal program and i enter 1234,
how could i convert %00110001_00110010_00110011_00110100 (or ascii 1234)
to the actual number %00000000_00000000_00000100_11010010 (or #1234)??
only way i can think is to make a lookup table.. is there any easier methods anyone knows about?
Thanks!!!
eg. Byte Variable[2]
Variable[0] = 1
Variable[1] = 2
Variable[2] = 3
and concatenate them into one Long so that the long equals the actual number #123
[original thread]
lets say im using a terminal program and i enter 1234,
how could i convert %00110001_00110010_00110011_00110100 (or ascii 1234)
to the actual number %00000000_00000000_00000100_11010010 (or #1234)??
only way i can think is to make a lookup table.. is there any easier methods anyone knows about?
Thanks!!!
Comments
so think of N.Byte[n] as an array..
N.byte[0] = 1
N.byte[1] = 2
N.byte[2] = 3
N.byte[3] = 4
but now im a little stumped, any ideas on how to take 1, 2, 3 and 4 and make them = 1234??
heres the code by the way:
either way you did give me an idea for a better way to collect those ascii bytes and convert them to actual numbers.
that is so much smaller and can read more ascii bytes thus making much larger numbers!
but im still stumped on how to make 1 + 2 = 12???????????
hey man thanks for the input, the code you posted looks oddly familiar to the code i just posted, proof that great minds do think alike! lol
[edit] well it did look similar for a second there, but i guess you're currently editing it :P
its not the conversion of an ascii byte to a single digit number thats causing me grief, its more or less the process of concatenating those collected bytes into a number inside of a Long
eg. #1 + #2 + #3 + #4 = #1234 (not #10)
- result starts with 0 and will now be 0 * 10 + 1 = 1
- result = 1 * 10 + 2 = 12
- result = 12 * 10 + 3 = 123
- result = 123 * 10 + 4 = 1234
- loop breaks (CR is not in [0..9]) and result is returned as 1234
I just re-used it for convenience.i must have been looking at this from a totally different angle and didnt grasp the simplicity of your example untill i actually plugged it in and gave it a go.
guess thats what sleep deprivation, 5am, no coffee and a boss whos giving unreal deadlines will do to a fella..
Thank you!!