Hi
example
(83)base 5 ------> ()base7
num     temp_num             result            carry
83           3* 1                   (3/7) =0        (3%7)=3
83            8*5                   (40/7)=5       (40%7)=5

result=0+5=5
carry= 3+5=8

   temp_carry=call convert for carry in which base is 10 and target base is
7
   (temp_carry will become 11)
   carry=temp_carry%10;
   (carry will become 1)
   result=result +temp_carry/10;
   (result will become 6)
    call convert for result in which base is 10 and target base is 7
   (result remain 6)
    result=result*10 + carry
    result 61
    return result

The logic would remain same for hexadecimal base also but implementation
would differ


On Wed, Aug 18, 2010 at 6:41 PM, sumant hegde <[email protected]> wrote:

> It is not clear whether 'subtraction' operation for given base B1 is
> granted defined or you should write code for it. If it is already defined,
> then simulating division (working wrt base B1) is easy (repeated
> subtraction). Then the normal procedure of converting a number from base 10
> to base b2 would work, where you divide the number by B2, note down the
> remainder, replace dividend by the quotient and repeat the process until the
> dividend becomes zero. Finally you concatenate the remainders in the reverse
> order.
>
> Ex: From 214 of base 5 to base 16.
> 16 is 31 of base 5 so,
> 214 / 31 =* **3* ;  214 % 31 = "21";  [ / and % work wrt base 5 which is
> to be programmed using repeated subtraction ]
> *3* / 31 = 0 ;   3 % 31 = "3";
>
> finally
> "3,21"
> or
> "3B" coz  B is hex equivalent of 21_base5
>
> OR
> in your simpler algo, is it not possible to define functions that 'get' and
> 'set' a particular digit, by using / and % ?
> Thanks,
> Summ
>
> On Tue, Aug 17, 2010 at 9:50 PM, luckyzoner <[email protected]> wrote:
>
>> I had proposed an algorithm of repeatedly subtracting 1 from the given
>> number and subsequently adding 1 to the new number initialised to 0,
>> till the given number becomes 0. However as soon as the digit reaches
>> the limit , the digit becomes 0 and you add 1 to the next digit. I was
>> not able to code it properly as i had to use int data type only. It
>> would have been easy if the array of integers was allowed to use.
>>
>> Pls suggest the code for the same or some better algo.
>>
>> Thanx
>> Lakshaya
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected]<algogeeks%[email protected]>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<algogeeks%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
Rahul singhal
RnD Engineer
Tejas Networks
Mobile- 09916969422

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to