• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 602
  • Last Modified:

Perl: Need to create random binary codes in a script

Hi everyone. Beautiful rainy day where I am.

I am able to create semi-random numbers like 4404315944, but I feel the need to create random binary numbers in a perl script.

Does anyone know how to translate any number, even if it's long like 4404315944?

I read something about ("%b",$number); but that doesn't work in a script.

Thank you very much for any help.

Best regards,

Dr34m3r
0
dr34m3rs
Asked:
dr34m3rs
  • 3
  • 2
1 Solution
 
TintinCommented:
Depends on your definition of binary.

printf("%b",123);

will output

1111011

ie:  base 2
0
 
dr34m3rsAuthor Commented:
How do you put that into a string?

Thank you very much.

Best regards,

Dr34m3r
0
 
dr34m3rsAuthor Commented:
would I do $str = printf("%b",$number);
0
 
TintinCommented:

dr34m3rs.

you should use sprintf *not* printf, ie:

$str = sprintf("%b",$number);
0
 
dr34m3rsAuthor Commented:
Awesome, thanks :)

That's exactly what I was looking for.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now