473,322 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Convert ascii to integer w/o atoi

hi, could someone pls help me how to convert ascii to integer without using the atoi function? (ex. X44).. i want to get the numbers and convert it to integers..

pls send me the code for C. tnx so much..
Feb 9 '07 #1
2 10593
Motoma
3,237 Expert 2GB
hi, could someone pls help me how to convert ascii to integer without using the atoi function? (ex. X44).. i want to get the numbers and convert it to integers..

pls send me the code for C. tnx so much..
You can do it character by character by subtracting the character '0' from each char.
Feb 9 '07 #2
AdrianH
1,251 Expert 1GB
hi, could someone pls help me how to convert ascii to integer without using the atoi function? (ex. X44).. i want to get the numbers and convert it to integers..

pls send me the code for C. tnx so much..
I won't do it for you, but will give you a hint. The characters '0' through '9' are consecutive, thus if you have a character and want to convert it to a digit value, first ensure that it is a digit by comparing the ascii value to fall between the values of '0' and '9' and then subtract '0' from it (the ascii value, not the number).

eg:
Expand|Select|Wrap|Line Numbers
  1. char ascii='9';
  2. int digit = ascii-'0'; /* digit now equals 9 */
  3.  
Hope this helps.


Adrian
Feb 9 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: news.hku.hk | last post by:
could you tell me how can i convet a string to integer?? #include <iostream> #include <string> using namespace std; int main(){ int integer; string buffer("123456789");
6
by: John Smith | last post by:
What's wrong with the use of atoi in the following code? Why do I get the error message: 'atoi' : cannot convert parameter 1 from 'char' to 'const char *' char cBuffer; void...
7
by: Golan | last post by:
Hi, I need to convert a Binary value to Decimal. I've been told that the value is an unsigned one. How can I do this? I use memcpy into an unsigned char variable, but when I print the value I got...
4
by: Kay | last post by:
how to convert int to char * ? I have found this in a web site. However, it doesn't work even I change itoa to atoi including stdlib.h char str; int i=567; str=itoa(i, str, 10);
7
by: Abhishek Jha | last post by:
How can we write a shortest program in c to convert given number to words format. example input 5012 Output: five thousand tewlve.
3
by: Convert TextBox.Text to Int32 Problem | last post by:
Need a little help here. I saw some related posts, so here goes... I have some textboxes which are designed for the user to enter a integer value. In "old school C" we just used the atoi function...
16
by: akarui.tomodachi | last post by:
What is the most easiest way to convert an integer value to ASCII character format ? I tried with sprintf(). It works. Is there any other way to do that ? Objective:: I like to convert an...
14
by: Drew | last post by:
Hi All: I know I am missing something easy but I can't find the problem! I have a program which reads an integer as input. The output of the program should be the sum of all the digits in the...
3
by: priyanka | last post by:
Hi there, I want to convert a String into integer. I get the string from a file using : string argNum; getline(inputStream,argNum); I now need to convert argNum into integer.
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.