math - subtract two numbers in base 3 in java -
this question has answer here:
- how work other base numbers in java? 5 answers
what's going on here? i'm trying subtract 2 integers in base 3 system.
int x=222211; int y=112222; string result = integer.tostring(x-y,3);
and result 109989
answer should 102212
it seems clear library doesn't think - result i'm getting base 10 result of subtraction. converting result base 3 gives me wildly incorrect result
this embarrassing, figured out seconds after posting this... maybe else out.
int x = integer.parseint("222211",n); int y = integer.parseint("112222",n); string result = integer.tostring(x-y,n);
convert numbers beforehand appropriate base
Comments
Post a Comment