Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Pomoc z zadaniem
avaterera
post 9.06.2013, 10:54:15
Post #1





Grupa: Zarejestrowani
Postów: 1
Pomógł: 0
Dołączył: 9.06.2013

Ostrzeżenie: (0%)
-----


Cześć. Czy ktoś mógłby mi pomóc z tym zadaniem? Chociaż doradzić smile.gif


An integer can be expressed in a positional representation with different radices. The most common radix is R = 10; other frequently used radices are 2, 8, 16. Any integer larger than 1 can be used as a radix, but with very large radices we may run out of symbols to represent digits (by convention, if digits 0..9 are insufficient, e.g. in radix 16, lower−case English letters are used to express larger digits: e.g. 'a' denotes a digit of value 10, 'f' denotes a digit of value 15).

Write a function:
function your_function($V,$R);
that returns a string containing the positional representation of the given value V in the given radix R. The representation should be big-endian; i.e. the first character of the string should correspond to the most significant digit of the representation.
For example, if V = 17 and R = 7, the function should return the string "23", because this is the representation of the number 17 in radix 7. If V = 62 and R = 21, the function should return "2k", because this is the representation of the number 62 in radix 21 (note that digit 'k' denotes value 20).
Assume that:
V is an integer within the range [0..200,000,000];
R is an integer within the range [2..36].
Complexity:
expected worst-case time complexity is O(log(V)/log®);
expected worst-case space complexity is O(log(V)/log®).
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 2)
SmokAnalog
post 9.06.2013, 11:12:42
Post #2





Grupa: Zarejestrowani
Postów: 1 707
Pomógł: 266
Dołączył: 3.07.2012
Skąd: Poznań

Ostrzeżenie: (0%)
-----


  1. function your_function($V, $R) {
  2. return base_convert($V, 10, $R);
  3. }

Ale pewnie to nie będzie potraktowane jako dobra odpowiedź wink.gif
Go to the top of the page
+Quote Post
mortus
post 9.06.2013, 13:42:07
Post #3





Grupa: Zarejestrowani
Postów: 2 178
Pomógł: 596
Dołączył: 25.09.2009
Skąd: Piwniczna-Zdrój

Ostrzeżenie: (0%)
-----


Wikipedia dokładnie opisuje sposób konwersji z systemu 10 do każdego innego systemu, algorytm jest naprawdę bardzo prosty.
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 14.08.2025 - 02:03