How do you convert a string to an unsigned long so that the unsigned long represents the characters in the string as 8bit numbers?
Thanks in advance.
EDIT: What I want to do is turn a string of 4 characters into a long of the same four characters in ASCII code format.
largely the same solution, making less assumptions on integral types sizes and checking the maximum string size that can be translated this way:
prints
the casting to
unsigned charis for the case your string contains high ASCII, i.e. values higher than 127, in which casecharwould be negative. Try the string"\226\226\226\226"instead and you will get incorrect result)EDIT: BTW, in your subject you say “and back”, so here’s the reverse transformation:
http://ideone.com/Cw7hF