# Introduction

Classically, booleans are one bit; true or false, 1 or 0. Leading zeros would just be redundant. For example, 001 means the same as 00001 or just 1.

# The 32-bit boolean

Given a truthy/falsey value, output the equivalent 32-bit boolean as a string. (Or as a number if for some reason your language supports leading zeros.)

Your program doesn't have to work for every truthy/falsy type, only what your programming language work best for.

# Example i/o

Input >> Output

truthy >> 00000000000000000000000000000001
falsey >> 00000000000000000000000000000000


## This is code-golf, so lowest bytes wins!

• Do we need to handle any possible truthy or falsey value, or just booleans? – xnor Jul 19 '17 at 0:31
• If my language supports types and has boolean can I use 1's (int) as truthy? – LiefdeWen Jul 19 '17 at 0:47
• @LiefdeWen of course – Graviton Jul 19 '17 at 5:59
• No longer duplicate as truthy/falsy inputs can be differen't for each answer/language. – Graviton Jul 19 '17 at 6:04
• I don't see why but huh, okay ~ – V. Courtois Jul 19 '17 at 10:10

# Jelly, 8 bytes

31”0x⁸ṆṆ


Try it online!

# Pyth, 9 bytes

+*31\0-1!


Test suite

Explanation:

+*31\0-1!
+*31\0-1!Q | Implicit Q (input)
*31\0     | repeat the character '0' 31 times
!Q | logical negation of input
-1   | subtract from 1
+          | concatenate


# Carrot, 7 bytes (Non-competing)

0^*30^#


Non-competing because there is no truthy/falsey type in Carrot at the moment. However, 1 and 0 are usually considered to be truthy/falsey so that is how I am expecting the input.

Explanation:

0   //Set the string stack to 0
^   //Change to operations mode
*30 //Duplicate the string stack 30 times
^   //Convert to string stack mode
#   //Add the input to the end of the stack
//Implicitly output the string stack


# Retina, 13 bytes

Ms.+
^
31$*0  Try it online! Assumes empty input is falsy and everything else is truthy, which is about all you can do when your only type is string. # MATL, 5 bytes 32&YB  Uses inputs 1/ 0, or T/ F. Try it online! ### Explanation 32 % Push 32 &YB % Convert implicit input to binary with 32 digits. Gives char output  # Lua, 30 bytes ("%032d"):format(b and 1 or 0)  Try it online! • i'm afraid that's not currently valid, you need to submit a full program or function like here – Felipe Nardi Batista Jul 19 '17 at 10:55 # Clojure, 28 bytes #(format "%031d" (if % 1 0))  Truthy is everything but nil and false # JavaScript, 25 bytes v=>'0'.repeat(31)+(v?1:0)  31 zeroes and conditionally add a 1 or 0. # ><>, 18 16 bytes <n0v?)*3a:l ;oi<  Try it online! # Explanation <n0v?)*3a:l ;oi< < | Move the direction left :l | Push the length of the stack onto the stack and duplicate it *3a | Push 10*3 onto the stack ) | Compare the stack top item is greater than the next stack item, push 1 is true else 0 v? | Check if stack top is 0, if 0 then jump else go to line 2 n0 | Print 0 (this will then loop line 1 again) ;oi< | Take input (1 byte), print input then end program  # C++14, 29 bytes [](int i){printf("%032d",i);}  At least bools are treated as 1 and 0 anyway :P # Excel, 2220 18 bytes Saved two bytes thanks to Wernisch and my own lack of critical analysis before posting. Saved two bytes by changing the formula completely =BASE(OR(A1),2,32)  It feels like there should be a shorter answer than this but I can't think of one. I found the shorter function that I felt must exist. • Can drop quotation marks for 2 bytes. =REPT(0,31)&1*A1 also handles falsy Empty cell. – Wernisch Jul 19 '17 at 12:52 # Befunge-98, 16 bytes '0' k:' k,&!!+,@  Try it online! Hexdump: 00000000: 2730 271e 6b3a 271e 6b2c 2621 212b 2c40 '0'.k:'.k,&!!+,@  output as space sperated digits, 9 bytes: ' k.&!!.@  Try it online! Hexdump: 00000000: 271e 6b2e 2621 212e 40 '.k.&!!.@  # Common Lisp, 71 bytes (defun f(i)(format t "~v@{~A~:*~}" 31 0)(prin1(cond((null i) 0)(t 1))))  Try it online! Because nil is a falsey value and anything else is truthy: (f nil) = 00000000000000000000000000000000 (f 123) = 00000000000000000000000000000001 (f t) = 00000000000000000000000000000001 ## Dyvil v0.33.0, 15 Bytes b=>"0"*31+b?1:0  Usage: let f: boolean -> String = b=>"0"*31++b?1:0 print f(true) // 00000000000000000000000000000001 print f(false) // 00000000000000000000000000000000  Explanation: Returns the string 0 repeated 31 times followed by 1 for true and 0 for false. This does not work in v0.34.0 anymore because it removes the + operator for Strings. # CJam, 6 bytes q31Te[  Try it Online Takes 1 for true and 0 for false. pads input with 31 0's on the left. q e# read input 31Te[ e# pad input with 31 0's on the left.  • You could do 31T instead of GF+0 to save 1 byte – Business Cat Jul 19 '17 at 17:07 • @BusinessCat Thanks, definite overthinking there! – geokavel Jul 19 '17 at 17:18 # Cubix, 24 bytes 1&u3I!|1^...0O;($\!vuO;@


Nonzero values are truthy in Cubix (as handled by !)

Try it online!

    1 &
u 3
I ! | 1 ^ . . .
0 O ; ( $\ ! v u O ; @  Explanation: • I : read in input as a number • !| : reflect go left if falsey, proceed if truthy falsey: • I : read in input; it's blank, so push 0 truthy: • 1 : push 1 both branches reach here: • ^3u1&\ : put 31 to the top of the stack and enter the loop Loop: • !v0O;($\ : if top is zero, go south, otherwise push 0, Output as a number, pop (;), decrement ((), then $kip \ and continue. Finally: • ;uO@ : pop the zero, Output the 0/1, and @ exits. # QBIC, 21 bytes [31|?A';]~:|?!1$\?@0


## Explanation

[31|        DO 31 times
?           PRINT
A          A$, which is later diefined as a literal 0 (represented as string, because QBasic spaces out printed numbers) '; Followed by a semicolon (to prevent newlines, tabs ect) ] Close the loop ~: IF the (numeric) input (is anything but 0) |?!1$       THEN print a literal 1 (cast to string, to prevent the spacing thingy again)
\?@0        ELSE print a 0; Here we finally define A$. We could use it earlier, because the complie-process from QBIC to QBasic moves literal declarations to the top of the file.  # Perl 6, 11 bytes '0'x 31~+?*  Try it online! • '0' x 31 produces the first 31 zeroes. • * is the argument to the function. ? coerces it to a boolean, and then + coerces that boolean into a number, either 0 or 1, which is appended to the leading zeroes with ~. # Groovy - 17 bytes A Groovy closure which takes a value and according to "groovy truth" outputs either a falsey or truthy value. {"0"*31+(it?1:0)} ### Explanation So, all we do is emit a string with 31 zeroes and then append either 0 or 1 onto the end, depending upon whether the input is false or true, according to "groovy truth". Try it online! ## K/Kona, 10 bytes Sadly not as clever as I'd have liked, but it works. (31#"0"),$


String-casts the input, and staples it to the end of 31 "0" chars

E.g.

k)(31#"0"),$1b "00000000000000000000000000000001" k)(31#"0"),$0b
"00000000000000000000000000000000"


# Perl 5, 17 + 1 (-p) = 18 bytes

$_=0 x31 .($_&&1)


Try it online!

# Julia, 13 bytes

~x=bin(x,32)


Nothing clever here, there is basically a built in for it.

# JavaScript (ES6), 25 bytes

b=>${+b}.padStart(0,32)  A different approach. Takes input as specifically true or false. ## Test Snippet let f= b=>${+b}.padStart(32,0)

console.log(true, f(true))
console.log(false, f(false))
.as-console-wrapper{max-height:100%!important}

• b=>'0'.repeat(31)+(+b)` is three bytes shorter. – Cows quack Jul 20 '17 at 6:18
• @Cowsquack That's already done here; I decided to just demonstrate a different method. – Justin Mariner Jul 20 '17 at 9:06