I want to print a padded to 32 bits word in binary in Racket. I know about printf and “~b”, but I want it padded to be 32 bits long each time. How do I do this?
Example
(printf "~b" 42)
=> 101010
Want: 00000000000000000000000000101010
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Here’s a concise way to do it with Racket 5.3.1 and above:
See racket/format for more details.
In older Racket versions, you can do this: