954,504 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Base converter

Hey Everyone,

Currently, I am working on a base converter that converts a binary to decimal or decimal to binary or binary to hex. However, for this I need to read the string or the number from the text file and convert it to a hex or binary or octal.

For example

int number,
fin>>number
//number = 101111001
//after reading i need to somehow get it into this form.
int a [x] = {1 0 1 1 1 1 0 0 1}


I need to separate this number into an array so i can do arithmetic on this. so I need it to be saved as int a [x] = {1 0 1 1 1 1 0 0 1}

k88joshi
Newbie Poster
24 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

Using '%' and '/' should be sufficent. First take a modulo 10 of number (and that is your last digit), then divide number by 10 (and you are left with number without last digit). And put that somehow in a for loop

Sci@phy
Posting Whiz in Training
279 posts since Sep 2008
Reputation Points: 110
Solved Threads: 43
 

And you have to swap the elements to get the array in reverse order.

Prabakar
Posting Whiz
342 posts since May 2008
Reputation Points: 94
Solved Threads: 33
 

http://www.daniweb.com/forums/thread148080.html
11 days ago, not in a galaxy far far away but on DaniWeb forum ;)..

ArkM
Postaholic
2,001 posts since Jul 2008
Reputation Points: 1,234
Solved Threads: 348
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You