Message Boards Message Boards


[✓] Get the nth element of the b-ary number?

Posted 2 months ago
4 Replies
1 Total Likes

Hi, everyone! I have used the programme pari/gp. But I cannot plot 3D graphs as easy as in programme Mathematica, so I would like to rewrite my codes into this programme language. The most important function is which gets the nth digit of a b-ary number also if it is a rational number. In the case of rational numbers I usually shift the whole number with base^50 and I floor it. The result will be shifted back by base^50. But how to get the nth element of the b-ary number? Thanks a lot! Best wishes, Kristóf

4 Replies

Please post a clear example of input and desired output. Nobody likes to guess...

Okay! Input: Bttest[100,3,3]; Output: 2; Because 100 in ternary number system seems like this: 10201 and its 3rd element is 2. The 1st argument is the number, the 2nd is the base of the number system, the last one shows which element is needed.

Could use IntegerDigits:

Bttest[nn_, base_, digit_] := 
 IntegerDigits[nn, base, digit][[1]]

In[6]:= Bttest[100, 3, 3]

(* Out[6]= 2 *)

This is doing no error checking though. And will require adjustment to handle noninteger input e.g. rationals.

It works. Thank you very much!

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract