Advertisement
paperline27

String to Binary.pl

Jan 21st, 2024
992
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.56 KB | Source Code | 0 0
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use Term::ANSIColor;
  5.  
  6. sub string_to_binary {
  7.     my $input_string = shift;
  8.     my $binary_representation = unpack("B*", $input_string);
  9.     return $binary_representation;
  10. }
  11.  
  12. print color('bold blue');
  13. print "Masukkan string yang ingin diubah ke representasi biner: ";
  14. print color('reset');
  15. my $user_input = <STDIN>;
  16. chomp($user_input);
  17.  
  18. my $binary_result = string_to_binary($user_input);
  19.  
  20. print color('bold yellow');
  21. print "Representasi Biner dari string '$user_input': 0b$binary_result\n";
  22. print color('reset');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement