thanx buddy...
that was helpful...
well i have one more doubt...

the method you gave above is cool if i take input from stream...
what if i pass a decimal or hexadecimal integer to a function from my main function..and then have to decide in that function whether the argument is a decimal or hexadecimal value...

for ex:

int main()
{
int count=2;
int x[]={0x620058, 0x665eaf};// or int x[]={123,44};
func(x,count);
return 0;
}

the func is....

void func(int x[],int count)
{
int a;
for(int i=0;i<count;i++)
a+=x;
}

here , how do i make sure that the integers passed in an array to the func() are in decimal or hexadecimal form???

An integer can be treated as either decimal, hexadecimal, or octal. As far as the program is concerned they are all the same. Its only us humans who know the difference when they are displayed, such as cout << hex << number << '\n';

Edited 3 Years Ago by pritaeas: fixed formatting

An integer can be treated as either decimal, hexadecimal, or octal. As far as the program is concerned they are all the same. Its only us humans who know the difference when they are displayed, such as cout << hex << number << '\n';

thats fine buddy!!!

but here the problem is that in my function i am randomly inputted an array of integers. Now these integers can either be decimal or hexadecimal..

the function should return that particular integer form(decimal or hexadecimal) after the operation.

when i perform the operation and return the value i have no idea of knowing whether it was inputted as decimal or hexadecimal.

what i want to know is that at the time of using the passed array in my function is there a method by which i can know whether it contains decimal or hexadecimal values????

Edited 3 Years Ago by Reverend Jim: Fixed formatting

Its not possible to distinguish between the two. After the number is input into the program they are both the same.

>>what i want to know is that at the time of using the passed array
>> in my function is there a method by which i can know whether it
>>contains decimal or hexadecimal values????

That is not possible. Just return the value and let the calling function do what it wants with it.

Its not possible to distinguish between the two. After the number is input into the program they are both the same.

>>what i want to know is that at the time of using the passed array
>> in my function is there a method by which i can know whether it
>>contains decimal or hexadecimal values????

That is not possible. Just return the value and let the calling function do what it wants with it.

hmmm...thnx :)

This article has been dead for over six months. Start a new discussion instead.