Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 567
  • 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

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

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