「テンプレート:Digit」の版間の差分

提供:脳科学辞典
ナビゲーションに移動 検索に移動
(1版)
 
(相違点なし)

2015年3月14日 (土) 12:15時点における最新版


This template gives the digit at a given position of a given positive integer, expressed in a specified numeral system.

  • The first parameter gives the number.
  • The second parameter is the position of the required digit (1 being the rightmost, 2 the one to the left, etc.).
  • The third parameter is the radix of the numeral system (default:10), 2 for binary, 8 for octal, 16 for hexadecimal.

For a radix > 10, the value is given in decimals, for instance, 15 in the hexadecimal system will give for the rightmost digit 15 (which should be "F")

Usage:
{{Digit|decimal integer|digit no|numeral system number}}
All parameters must be positive integers.

Examples

  • {{digit|13|1|2}} → 1
  • {{digit|13|2|2}} → 0
  • {{digit|13|3|2}} → 1
  • {{digit|13|4|2}} → 1
  • {{digit|9002543211234567|1}} → 7
  • {{digit|9002543211234567|2}} → 6
  • {{digit|9002543211234567|3}} → 5
  • {{digit|9002543211234567|4}} → 4
  • {{digit|9002543211234567|5}} → 3
  • {{digit|9002543211234567|6}} → 2
  • {{digit|9002543211234567|7}} → 1
  • {{digit|9002543211234567|8}} → 1
  • {{digit|9002543211234567|9}} → 2
  • {{digit|9002543211234567|10}} → 3
  • {{digit|9002543211234567|11}} → 4
  • {{digit|9002543211234567|12}} → 5
  • {{digit|9002543211234567|13}} → 2
  • {{digit|9002543211234567|14}} → 0
  • {{digit|9002543211234567|15}} → 0
  • {{digit|9002543211234567|16}} → 9
  • {{digit|9002543211234567|17}} → 0
  • {{digit|9002543211234567|18}} → 0
  • {{digit|9002543211234567|19}} → 0
  • {{hex|9002543211234567}}1.ffbc3ee2e4507hex*2^52
  • {{digit|9002543211234567|1|16}} → 7
  • {{digit|9002543211234567|2|16}} → 0
  • {{digit|9002543211234567|3|16}} → 5
  • {{digit|9002543211234567|4|16}} → 4
  • {{digit|9002543211234567|5|16}} → 14
  • {{digit|9002543211234567|6|16}} → 2
  • {{digit|9002543211234567|7|16}} → 14
  • {{digit|9002543211234567|8|16}} → 14
  • {{digit|9002543211234567|9|16}} → 3
  • {{digit|9002543211234567|10|16}} → 12
  • {{digit|9002543211234567|11|16}} → 11
  • {{digit|9002543211234567|12|16}} → 15
  • {{digit|9002543211234567|13|16}} → 15
  • {{digit|9002543211234567|14|16}} → 1
  • {{digit|9002543211234567|15|16}} → 0

Large numbers of type integer

Special care has been taken to make the result exact even for large numbers of type integer.

  • {{digit|trunc(9134567890e9)+trunc123456789|1}} → 9
  • {{#expr:trunc16*trunc(9002543211234567)+trunc7}} → 144040691379753079
  • {{digit|trunc((trunc(1440406913))e trunc(7+1)+trunc79753079)|1}} → 9
  • {{digit|trunc((trunc(1440406913))e trunc(7+1)+trunc79753079)|2}} → 7
  • {{digit|trunc((trunc(1440406913))e trunc(7+1)+trunc79753079)|3}} → 0
  • {{digit|trunc((trunc(1440406913))e trunc(7+1)+trunc79753079)|4}} → 3
  • {{digit|trunc((trunc(1440406913))e trunc(7+1)+trunc79753079)|5}} → 5
  • {{digit|trunc((trunc(1440406913))e trunc(7+1)+trunc79753079)|6}} → 7
  • {{digit|trunc((trunc(1440406913))e trunc(7+1)+trunc79753079)|7}} → 9
  • {{digit|trunc((trunc(1440406913))e trunc(7+1)+trunc79753079)|8}} → 7
  • {{digit|trunc((trunc(1440406913))e trunc(7+1)+trunc79753079)|9}} → 3
  • {{digit|trunc((trunc(1440406913))e trunc(7+1)+trunc79753079)|10}} → 1
  • {{digit|trunc((trunc(1440406913))e trunc(7+1)+trunc79753079)|11}} → 9
  • {{digit|trunc((trunc(1440406913))e trunc(7+1)+trunc79753079)|12}} → 6
  • {{digit|trunc((trunc(1440406913))e trunc(7+1)+trunc79753079)|13}} → 0
  • {{digit|trunc((trunc(1440406913))e trunc(7+1)+trunc79753079)|14}} → 4
  • {{digit|trunc((trunc(1440406913))e trunc(7+1)+trunc79753079)|15}} → 0
  • {{digit|trunc((trunc(1440406913))e trunc(7+1)+trunc79753079)|16}} → 4
  • {{digit|trunc((trunc(1440406913))e trunc(7+1)+trunc79753079)|17}} → 4
  • {{digit|trunc((trunc(1440406913))e trunc(7+1)+trunc79753079)|18}} → 1
  • {{digit|trunc((trunc(1440406913))e trunc(7+1)+trunc79753079)|19}} → 0
  • {{digit|trunc((trunc(1440406913))e trunc(7+1)+trunc79753079)|1|1e3}} → 79
  • {{digit|trunc((trunc(1440406913))e trunc(7+1)+trunc79753079)|2|1e3}} → 753
  • {{digit|trunc((trunc(1440406913))e trunc(7+1)+trunc79753079)|3|1e3}} → 379
  • {{digit|trunc((trunc(1440406913))e trunc(7+1)+trunc79753079)|4|1e3}} → 691
  • {{digit|trunc((trunc(1440406913))e trunc(7+1)+trunc79753079)|5|1e3}} → 40
  • {{digit|trunc((trunc(1440406913))e trunc(7+1)+trunc79753079)|6|1e3}} → 144
  • {{digit|trunc((trunc(1440406913))e trunc(7+1)+trunc79753079)|7|1e3}} → 0
  • {{digit|trunc90140406913e8+trunc79753079|7|1e3}} → 9
  • {{digit|trunc90140406913e8+trunc79753079|8|1e3}} → 0
  • {{hex|trunc1440406913e8+trunc79753079}}1.ffbc3ee2e4507hex*2^56
  • {{digit|trunc((trunc(1440406913))e trunc(7+1)+trunc79753079)|1|16}} → 7
  • {{digit|trunc((trunc(1440406913))e trunc(7+1)+trunc79753079)|2|16}} → 7
  • {{digit|trunc((trunc(1440406913))e trunc(7+1)+trunc79753079)|3|16}} → 0
  • {{digit|trunc((trunc(1440406913))e trunc(7+1)+trunc79753079)|4|16}} → 5
  • {{digit|trunc((trunc(1440406913))e trunc(7+1)+trunc79753079)|5|16}} → 4
  • {{digit|trunc((trunc(1440406913))e trunc(7+1)+trunc79753079)|6|16}} → 14
  • {{digit|trunc((trunc(1440406913))e trunc(7+1)+trunc79753079)|7|16}} → 2
  • {{digit|trunc((trunc(1440406913))e trunc(7+1)+trunc79753079)|8|16}} → 14
  • {{digit|trunc((trunc(1440406913))e trunc(7+1)+trunc79753079)|9|16}} → 14
  • {{digit|trunc((trunc(1440406913))e trunc(7+1)+trunc79753079)|10|16}} → 3
  • {{digit|trunc((trunc(1440406913))e trunc(7+1)+trunc79753079)|11|16}} → 12
  • {{digit|trunc((trunc(1440406913))e trunc(7+1)+trunc79753079)|12|16}} → 11
  • {{digit|trunc((trunc(1440406913))e trunc(7+1)+trunc79753079)|13|16}} → 15
  • {{digit|trunc((trunc(1440406913))e trunc(7+1)+trunc79753079)|14|16}} → 15
  • {{digit|trunc((trunc(1440406913))e trunc(7+1)+trunc79753079)|15|16}} → 1

Limitation

This template applies function mod with as second argument the third parameter and a power of it. Therefore it does not work properly if one of these is equal to one of the values for which mod does not work properly. Known values are 2^n-1 and 2^n+1 for n >= 32:

  • {{digit|7|1|2^32-1}} → 7
  • {{digit|2^40|1|2^32-1}} → 256
  • {{digit|2^40|2|2^32-1}} → 256

At least for powers with base <= 30 there are no errors with the test value 17 as first argument, see Help:Mod/powers.