math - subtract two numbers in base 3 in java -


this question has answer here:

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

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -