Advertisement
Guest User

Untitled

a guest
Dec 28th, 2014
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. # encoding: utf-8
  2. #
  3. # Licensed under GPLv2
  4. # Author: Hüseyin TEKINASLAN <huseyintekinaslan@gmail.com>
  5. #
  6. # This program is free software; you can redistribute it and/or modify it under
  7. # the terms of the GNU General Public License as published by the Free
  8. # Software Foundation; either version 2 of the License, or (at your option)
  9. # any later version.
  10. #
  11.  
  12. class Hclass
  13. def initialize(number, base)
  14. @number = number
  15. @base = base
  16. end
  17. def base
  18. array0 = Array.new
  19. if @number.is_a?(Fixnum) and @base.is_a?(Fixnum)
  20. if @base != 0 and @base != 1 and @base > 1 and @number >= 0
  21. instance = @number
  22. while true
  23. remaining = instance - ((instance / @base) * @base)
  24. instance = instance / @base
  25. if instance > 1
  26. array0 << remaining
  27. else
  28. array0 << remaining << instance
  29. break
  30. end
  31. end
  32. if array0[-1] == 0 then array0.pop(1) end
  33. return array0.reverse.join
  34. else
  35. return """Olası hata durumlarınız:
  36. * Taban 0 veya 1 olabilir.
  37. * Girdiğiniz sayı negatif olabilir.
  38. Girdilerinizi kontrol ediniz."""
  39. end
  40. else
  41. return "Sayı veya taban tamsayı olmalıdır."
  42. end
  43. end
  44. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement