Wrox Programmer Forums
|
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old July 9th, 2008, 05:22 PM
Friend of Wrox
 
Join Date: Mar 2008
Posts: 133
Thanks: 15
Thanked 1 Time in 1 Post
Send a message via ICQ to iceman90289 Send a message via AIM to iceman90289
Default Base Converter

ok so i have a program i am working on(obviously) and i am in the planning phase right now so i dont have a mess of code to retype anyways. but i have the number in hexidecimal(a89ef) and put it into decimal(690671), and i want to put each digit from the decimal value into an array, element[0] being the 1, and element[1] being the 7, and so on. so how do i fill my array with each individual digit?
thanks in advance

Reply With Quote
  #2 (permalink)  
Old July 9th, 2008, 07:44 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Code:
int[] element = new int[10];
int num = #a89ef; // or use decimal 690671
for ( int i = 0; i < 10; ++i )
{
    element[i] = num % 10;
    num /= 10;
}
I'm not a C# person, so if minor syntax error apologies. But concept works for 32 bit integers, which can't exceed 10 decimal digits. Doesn't handle negative numbers.
Reply With Quote
The Following User Says Thank You to Old Pedant For This Useful Post:
iceman90289 (February 5th, 2009)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Image Converter ehabinl C++ Programming 0 October 8th, 2006 01:25 AM
converter anukagni ASP.NET 1.0 and 1.1 Basics 1 August 28th, 2006 07:43 AM
Language Converter Sunbin PHP How-To 4 July 11th, 2004 10:26 PM
C program Currency Converter lgschulz C++ Programming 1 July 1st, 2003 01:21 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.