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

**URL:** <https://community.wolfram.com/t/get-the-nth-element-of-the-b-ary-number/12727>\
**Category:** Questions\
**Tags:** graphics-and-visualization, graphs-and-networks\
**Created:** [July 11, 2018, 4:29am UTC](https://community.wolfram.com/t/get-the-nth-element-of-the-b-ary-number/12727 "2018-07-11T04:29:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vkristof211](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/vkristof211/32/11360_2.png) [@vkristof211](https://community.wolfram.com/u/vkristof211)\
**Post date:** [July 11, 2018, 4:29am UTC](https://community.wolfram.com/t/get-the-nth-element-of-the-b-ary-number/12727/1 "2018-07-11T04:29:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![danl](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/danl/32/41267_2.png) [@danl](https://community.wolfram.com/u/danl)\
**Post date:** [July 11, 2018, 4:33pm UTC](https://community.wolfram.com/t/get-the-nth-element-of-the-b-ary-number/12727/2 "2018-07-11T16:33:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![vkristof211](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/vkristof211/32/11360_2.png) [@vkristof211](https://community.wolfram.com/u/vkristof211)\
**Post date:** [July 11, 2018, 5:20pm UTC](https://community.wolfram.com/t/get-the-nth-element-of-the-b-ary-number/12727/3 "2018-07-11T17:20:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![danl](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/danl/32/41267_2.png) [@danl](https://community.wolfram.com/u/danl)\
**Post date:** [July 11, 2018, 5:31pm UTC](https://community.wolfram.com/t/get-the-nth-element-of-the-b-ary-number/12727/4 "2018-07-11T17:31:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![vkristof211](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/vkristof211/32/11360_2.png) [@vkristof211](https://community.wolfram.com/u/vkristof211)\
**Post date:** [July 11, 2018, 6:23pm UTC](https://community.wolfram.com/t/get-the-nth-element-of-the-b-ary-number/12727/5 "2018-07-11T18:23:31Z")

</div>

It works. Thank you very much!
