Message Boards Message Boards

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

Posted 6 years ago

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
4 Replies

It works. Thank you very much!

POSTED BY: Kristóf Vörös

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
POSTED BY: Kristóf Vörös

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

POSTED BY: Daniel Lichtblau
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract