Message Boards Message Boards

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

GROUPS:

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

POSTED BY: Kristóf Vörös
Answer
11 days ago

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

POSTED BY: Daniel Lichtblau
Answer
10 days ago

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.

POSTED BY: Kristóf Vörös
Answer
10 days ago

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.

POSTED BY: Daniel Lichtblau
Answer
10 days ago

It works. Thank you very much!

POSTED BY: Kristóf Vörös
Answer
10 days ago

Group Abstract Group Abstract