Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String to Integer

Status
Not open for further replies.

aagaa

Programmer
Joined
Sep 16, 2002
Messages
2
Location
US
I have a basic knowledge of c++, but I haven't done any real programming for a couple years or so. I know there's a function that can convert strings to integers, but I can't remember what it is...so, I'd appreciate it if someone could tell me this and/or direct me to a database with several commands and descriptions of their uses.

Just to give you an idea of what I'm trying to do, I'm trying to program myself a calculator to convert between hex, binary, and decimal. I know there are many available ones, but I'm trying to get back into programming a bit, and I figured this could be a good start. If there's a better way to convert between number bases, then I'd be open to suggestions for that too. Thanks
 
Try to use the function "atoi".
with it you can convert a string to an int.
And you can also make some base coversion with it to.
 
'cause you also want to use HEX you could make it more general :
with "101" (decimal) do : 1 + 0*10 + 1*10*10
with "101" (hex) do : 1 + 0*16 + 1*16*16
with "101" (binary) do : 1 + 0*2 + 1*2*2

scan the string and interpret (not convert, 'cause "1A2F" won't do) char by char from right to left, then use the
formula from above.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top