On Mon, 26 Apr 2004 00:39:21 +0000, Willem wrote:
On Sun, 25 Apr 2004 17:26:03 -0700, Ben Pfaff <bl*@cs.stanford.edu>
wrote:
Willem <sw******@hotmail.com> writes:
What is the best way to calculate an ascii string into an integer (not
talking about an atoi conversion):
For examle if I have the ascii string: "/b" then in hex it would be
2F7A and if I convert that to decimal I would get 12154.
Assuming that the string is already in ASCII:
(s[0] << 8) | s[1]
Otherwise you'll have to convert the string to ASCII first.
Holy cow thank you,
That was so simple! Thank you so very much - now that it works I have
to figure out why it works.
First, don't top-post. Replies go /below/ what you are replying to. I've
fixed it because it's very annoying to most people on this group.
Second, /why/ it works is an exercise in binary logic. Draw it on a paper,
remembering that in ASCII, each character is eight bits wide, and that |
is the bitwise OR operator.
(If you can /see/ why it works, bitwise operations will forever be much
easier for you. And finding it out for yourself should be rewarding.
Otherwise, you can make more money getting an MBA instead of programming.)
--
yvoregnevna gjragl-guerr gjb-gubhfnaq guerr ng lnubb qbg pbz
To email me, rot13 and convert spelled-out numbers to numeric form.
"Makes hackers smile" makes hackers smile.