473,413 Members | 1,727 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,413 software developers and data experts.

How to break up a number into it's digits and analyze it.

I have a list of numbers i need to analyze, however for this just assume I only need to analyze one. I am given a six to nine digit number which I need to break into pieces from right to left. The right three digits represent an ASCII value while the middle represent a y position and the left three represent the x position, if there are no "left three" the number is assumed to be zero for the x value.

I was thinking that it might be possible to do this by breaking the number into its digits then placing each digit in an array, however I don't know how to do this if it is possible.

Does anyone have suggestions how to do this? Any feedback would be greatly appreciated.
Oct 15 '10 #1
3 3507
weaknessforcats
9,208 Expert Mod 8TB
Yes you can break your integer into an array of character variables.

If you are using C, then do this with a all to itoa().

If you are usign C++, create a stringstream. Then insert your integer into the stream. Then extract from the stream to a char array.
Oct 15 '10 #2
donbock
2,426 Expert 2GB
Is that six-to-nine-digit number an actual integer number (an unsigned long) or is it a string of decimal-ASCII characters?

You want to break this one number into three pieces: x position, y position, and ASCII value. Each piece consists of three digits. Do you prefer to express the value of each piece as an actual integer number (an int) or as a string of decimal-ASCII characters?
Oct 15 '10 #3
Expand|Select|Wrap|Line Numbers
  1. long yournumber = 987654321;
  2. char str[20];
  3. int x,y,asc;
  4.  
  5. sprintf( str, "%ld", yournumber );
  6. sscanf( str, "%3d%3d%3d", &x, &y, &asc );
Oct 16 '10 #4

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

Similar topics

6
by: Chris Michael | last post by:
I've got a string of numbers, say 123456 (the actually number is 12 digits long). I need to calculate the sum of each individual number in the string of numbers, so in the example of 123456 the sum...
13
by: CHRISTOF WARLICH | last post by:
Hi, does anyone know of an efficient way to find the number of digits (i.e. the most significant position that is 1) of a binary number? What I found so far is: - digits = (int) log2(number),...
9
by: Alex Willmer | last post by:
When reporting file sizes to the user, it's nice to print '16.1 MB', rather than '16123270 B'. This is the behaviour the command 'df -h' implements. There's no python function that I could find to...
2
by: Shannon Scheer | last post by:
Hi i am converting some data in our POS System which currently uses 13 digits for UPC codes (eg 0000000001234) however our Barcode software requires the UPC to be 12 digits (000000001234) I...
6
by: Jovo Mirkovic | last post by:
Hi, I have to make a program which will generate 100,000 different ID numbers (for example 2345-9341-0903-3432-3432 ...) It must be really different, I meen it can not be a similar (like...
109
by: jmcgill | last post by:
Hello. Is there a method for computing the number of digits, in a given numeric base, of N factorial, without actually computing the factorial? For example, 8! has 5 digits in base 10; 10! has...
14
by: RonHouston | last post by:
Hi, I was wondering if someone could help me on this one. Is there anyway to format a string/integer etc so that it always outputs a 4 digits number? thank you. Ron.
5
by: trifinite | last post by:
I am having difficulty understanding why the following code does not result in error. The code below simply traverses a string, extracting any continuous sequence of digits (0 - 9) and placing them...
3
by: ccarter45 | last post by:
I really need help with this. Your tips are greatly appreciated: import java.util.Scanner; public class PhoneNumbers { public static void main(String args){ Scanner input; ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.