base_convert_basic.phpt 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. --TEST--
  2. Test base_convert() - basic function tests base_convert()
  3. --FILE--
  4. <?php
  5. $frombase = array(2,8,10,16,36);
  6. $tobase = array(2,8,10,16,36);
  7. $values = array(10,
  8. 27,
  9. 39,
  10. 039,
  11. 0x5F,
  12. "10",
  13. "27",
  14. "39",
  15. "5F",
  16. "3XYZ"
  17. );
  18. for ($f= 0; $f < count($frombase); $f++) {
  19. echo "\n...from base is ", $frombase[$f], "\n";
  20. for ($t= 0; $t < count($tobase); $t++) {
  21. echo "......to base is ", $tobase[$t], "\n";
  22. for ($i =0; $i < count($values); $i++){
  23. $res = base_convert($values[$i],$frombase[$f],$tobase[$t]);
  24. echo ".........value= ", $values[$i], " res = ", $res, "\n";
  25. }
  26. }
  27. }
  28. ?>
  29. --EXPECTF--
  30. ...from base is 2
  31. ......to base is 2
  32. .........value= 10 res = 10
  33. .........value= 27 res = 0
  34. .........value= 39 res = 0
  35. .........value= 3 res = 0
  36. .........value= 95 res = 0
  37. .........value= 10 res = 10
  38. .........value= 27 res = 0
  39. .........value= 39 res = 0
  40. .........value= 5F res = 0
  41. .........value= 3XYZ res = 0
  42. ......to base is 8
  43. .........value= 10 res = 2
  44. .........value= 27 res = 0
  45. .........value= 39 res = 0
  46. .........value= 3 res = 0
  47. .........value= 95 res = 0
  48. .........value= 10 res = 2
  49. .........value= 27 res = 0
  50. .........value= 39 res = 0
  51. .........value= 5F res = 0
  52. .........value= 3XYZ res = 0
  53. ......to base is 10
  54. .........value= 10 res = 2
  55. .........value= 27 res = 0
  56. .........value= 39 res = 0
  57. .........value= 3 res = 0
  58. .........value= 95 res = 0
  59. .........value= 10 res = 2
  60. .........value= 27 res = 0
  61. .........value= 39 res = 0
  62. .........value= 5F res = 0
  63. .........value= 3XYZ res = 0
  64. ......to base is 16
  65. .........value= 10 res = 2
  66. .........value= 27 res = 0
  67. .........value= 39 res = 0
  68. .........value= 3 res = 0
  69. .........value= 95 res = 0
  70. .........value= 10 res = 2
  71. .........value= 27 res = 0
  72. .........value= 39 res = 0
  73. .........value= 5F res = 0
  74. .........value= 3XYZ res = 0
  75. ......to base is 36
  76. .........value= 10 res = 2
  77. .........value= 27 res = 0
  78. .........value= 39 res = 0
  79. .........value= 3 res = 0
  80. .........value= 95 res = 0
  81. .........value= 10 res = 2
  82. .........value= 27 res = 0
  83. .........value= 39 res = 0
  84. .........value= 5F res = 0
  85. .........value= 3XYZ res = 0
  86. ...from base is 8
  87. ......to base is 2
  88. .........value= 10 res = 1000
  89. .........value= 27 res = 10111
  90. .........value= 39 res = 11
  91. .........value= 3 res = 11
  92. .........value= 95 res = 101
  93. .........value= 10 res = 1000
  94. .........value= 27 res = 10111
  95. .........value= 39 res = 11
  96. .........value= 5F res = 101
  97. .........value= 3XYZ res = 11
  98. ......to base is 8
  99. .........value= 10 res = 10
  100. .........value= 27 res = 27
  101. .........value= 39 res = 3
  102. .........value= 3 res = 3
  103. .........value= 95 res = 5
  104. .........value= 10 res = 10
  105. .........value= 27 res = 27
  106. .........value= 39 res = 3
  107. .........value= 5F res = 5
  108. .........value= 3XYZ res = 3
  109. ......to base is 10
  110. .........value= 10 res = 8
  111. .........value= 27 res = 23
  112. .........value= 39 res = 3
  113. .........value= 3 res = 3
  114. .........value= 95 res = 5
  115. .........value= 10 res = 8
  116. .........value= 27 res = 23
  117. .........value= 39 res = 3
  118. .........value= 5F res = 5
  119. .........value= 3XYZ res = 3
  120. ......to base is 16
  121. .........value= 10 res = 8
  122. .........value= 27 res = 17
  123. .........value= 39 res = 3
  124. .........value= 3 res = 3
  125. .........value= 95 res = 5
  126. .........value= 10 res = 8
  127. .........value= 27 res = 17
  128. .........value= 39 res = 3
  129. .........value= 5F res = 5
  130. .........value= 3XYZ res = 3
  131. ......to base is 36
  132. .........value= 10 res = 8
  133. .........value= 27 res = n
  134. .........value= 39 res = 3
  135. .........value= 3 res = 3
  136. .........value= 95 res = 5
  137. .........value= 10 res = 8
  138. .........value= 27 res = n
  139. .........value= 39 res = 3
  140. .........value= 5F res = 5
  141. .........value= 3XYZ res = 3
  142. ...from base is 10
  143. ......to base is 2
  144. .........value= 10 res = 1010
  145. .........value= 27 res = 11011
  146. .........value= 39 res = 100111
  147. .........value= 3 res = 11
  148. .........value= 95 res = 1011111
  149. .........value= 10 res = 1010
  150. .........value= 27 res = 11011
  151. .........value= 39 res = 100111
  152. .........value= 5F res = 101
  153. .........value= 3XYZ res = 11
  154. ......to base is 8
  155. .........value= 10 res = 12
  156. .........value= 27 res = 33
  157. .........value= 39 res = 47
  158. .........value= 3 res = 3
  159. .........value= 95 res = 137
  160. .........value= 10 res = 12
  161. .........value= 27 res = 33
  162. .........value= 39 res = 47
  163. .........value= 5F res = 5
  164. .........value= 3XYZ res = 3
  165. ......to base is 10
  166. .........value= 10 res = 10
  167. .........value= 27 res = 27
  168. .........value= 39 res = 39
  169. .........value= 3 res = 3
  170. .........value= 95 res = 95
  171. .........value= 10 res = 10
  172. .........value= 27 res = 27
  173. .........value= 39 res = 39
  174. .........value= 5F res = 5
  175. .........value= 3XYZ res = 3
  176. ......to base is 16
  177. .........value= 10 res = a
  178. .........value= 27 res = 1b
  179. .........value= 39 res = 27
  180. .........value= 3 res = 3
  181. .........value= 95 res = 5f
  182. .........value= 10 res = a
  183. .........value= 27 res = 1b
  184. .........value= 39 res = 27
  185. .........value= 5F res = 5
  186. .........value= 3XYZ res = 3
  187. ......to base is 36
  188. .........value= 10 res = a
  189. .........value= 27 res = r
  190. .........value= 39 res = 13
  191. .........value= 3 res = 3
  192. .........value= 95 res = 2n
  193. .........value= 10 res = a
  194. .........value= 27 res = r
  195. .........value= 39 res = 13
  196. .........value= 5F res = 5
  197. .........value= 3XYZ res = 3
  198. ...from base is 16
  199. ......to base is 2
  200. .........value= 10 res = 10000
  201. .........value= 27 res = 100111
  202. .........value= 39 res = 111001
  203. .........value= 3 res = 11
  204. .........value= 95 res = 10010101
  205. .........value= 10 res = 10000
  206. .........value= 27 res = 100111
  207. .........value= 39 res = 111001
  208. .........value= 5F res = 1011111
  209. .........value= 3XYZ res = 11
  210. ......to base is 8
  211. .........value= 10 res = 20
  212. .........value= 27 res = 47
  213. .........value= 39 res = 71
  214. .........value= 3 res = 3
  215. .........value= 95 res = 225
  216. .........value= 10 res = 20
  217. .........value= 27 res = 47
  218. .........value= 39 res = 71
  219. .........value= 5F res = 137
  220. .........value= 3XYZ res = 3
  221. ......to base is 10
  222. .........value= 10 res = 16
  223. .........value= 27 res = 39
  224. .........value= 39 res = 57
  225. .........value= 3 res = 3
  226. .........value= 95 res = 149
  227. .........value= 10 res = 16
  228. .........value= 27 res = 39
  229. .........value= 39 res = 57
  230. .........value= 5F res = 95
  231. .........value= 3XYZ res = 3
  232. ......to base is 16
  233. .........value= 10 res = 10
  234. .........value= 27 res = 27
  235. .........value= 39 res = 39
  236. .........value= 3 res = 3
  237. .........value= 95 res = 95
  238. .........value= 10 res = 10
  239. .........value= 27 res = 27
  240. .........value= 39 res = 39
  241. .........value= 5F res = 5f
  242. .........value= 3XYZ res = 3
  243. ......to base is 36
  244. .........value= 10 res = g
  245. .........value= 27 res = 13
  246. .........value= 39 res = 1l
  247. .........value= 3 res = 3
  248. .........value= 95 res = 45
  249. .........value= 10 res = g
  250. .........value= 27 res = 13
  251. .........value= 39 res = 1l
  252. .........value= 5F res = 2n
  253. .........value= 3XYZ res = 3
  254. ...from base is 36
  255. ......to base is 2
  256. .........value= 10 res = 100100
  257. .........value= 27 res = 1001111
  258. .........value= 39 res = 1110101
  259. .........value= 3 res = 11
  260. .........value= 95 res = 101001001
  261. .........value= 10 res = 100100
  262. .........value= 27 res = 1001111
  263. .........value= 39 res = 1110101
  264. .........value= 5F res = 11000011
  265. .........value= 3XYZ res = 101100111010111011
  266. ......to base is 8
  267. .........value= 10 res = 44
  268. .........value= 27 res = 117
  269. .........value= 39 res = 165
  270. .........value= 3 res = 3
  271. .........value= 95 res = 511
  272. .........value= 10 res = 44
  273. .........value= 27 res = 117
  274. .........value= 39 res = 165
  275. .........value= 5F res = 303
  276. .........value= 3XYZ res = 547273
  277. ......to base is 10
  278. .........value= 10 res = 36
  279. .........value= 27 res = 79
  280. .........value= 39 res = 117
  281. .........value= 3 res = 3
  282. .........value= 95 res = 329
  283. .........value= 10 res = 36
  284. .........value= 27 res = 79
  285. .........value= 39 res = 117
  286. .........value= 5F res = 195
  287. .........value= 3XYZ res = 183995
  288. ......to base is 16
  289. .........value= 10 res = 24
  290. .........value= 27 res = 4f
  291. .........value= 39 res = 75
  292. .........value= 3 res = 3
  293. .........value= 95 res = 149
  294. .........value= 10 res = 24
  295. .........value= 27 res = 4f
  296. .........value= 39 res = 75
  297. .........value= 5F res = c3
  298. .........value= 3XYZ res = 2cebb
  299. ......to base is 36
  300. .........value= 10 res = 10
  301. .........value= 27 res = 27
  302. .........value= 39 res = 39
  303. .........value= 3 res = 3
  304. .........value= 95 res = 95
  305. .........value= 10 res = 10
  306. .........value= 27 res = 27
  307. .........value= 39 res = 39
  308. .........value= 5F res = 5f
  309. .........value= 3XYZ res = 3xyz