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}

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.