Binary digits: Difference between revisions
Content added Content deleted
Line 246: | Line 246: | ||
=={{header|Ada}}== |
=={{header|Ada}}== |
||
<lang Ada>with ada.text_io;use ada.text_io; |
|||
This solution uses the [Base_Conversion package [https://rosettacode.org/wiki/Find_palindromic_numbers_in_both_binary_and_ternary_bases#Base_Conversion]] from the [find palindromic numbers [https://rosettacode.org/wiki/Find_palindromic_numbers_in_both_binary_and_ternary_bases]] task. |
|||
⚫ | |||
<lang Ada>with Ada.Text_IO, Base_Conversion; |
|||
⚫ | |||
(if n=0 then "0" elsif n=1 then "1" else bin_image (n/2) & bin_image (n mod 2)); |
|||
test_values : array (1..3) of Natural := (5,50,9000); |
|||
⚫ | |||
package BC is new Base_Conversion(Integer); |
|||
⚫ | |||
(BC.Image(N, Base => 2)); |
|||
begin |
begin |
||
for test of test_values loop put_line ("Output for" & test'img &" is " & bin_image (test)); end loop; |
|||
Ada.Text_IO.Put_Line(To_Binary(5)); -- 101 |
|||
⚫ | |||
Ada.Text_IO.Put_Line(To_Binary(50)); -- 110010 |
|||
Ada.Text_IO.Put_Line(To_Binary(9000)); -- 10001100101000 |
|||
{{out}} |
|||
⚫ | |||
<pre> |
|||
Output for 5 is 101 |
|||
Output for 50 is 110010 |
|||
Output for 9000 is 10001100101000 |
|||
</pre> |
|||
=={{header|Aime}}== |
=={{header|Aime}}== |