g | x | w | all
Bytes Lang Time Link
122Pascal240727T200012ZKai Burg
004Thunno 2230624T140900ZThe Thon
005Vyxal221015T094125ZDialFros
007Carrot170719T090022ZTheLetha
020AWK210522T013319ZPedro Ma
082Starry210521T165505ZJay Ryan
012Julia 0.6170822T020254ZFrames C
005Stax210520T073353ZRazetime
025JavaScript ES6170719T112518ZJustin M
nanPerl 5170805T043735ZXcali
009MY170719T224318ZAdalynn
029C# .NET Core170719T005146ZLiefdeWe
011Japt170719T014549ZOliver
015Python 3170719T001505Zwrymug
008Braingolf170719T085631ZMayube
040Java170719T123945ZV. Court
010K/Kona170720T112255ZSimon Ma
032Scala170719T101917ZV. Court
036Brainfuck170720T052323ZRapha
011Octave170719T131615Zrahnema1
013Ly170719T015016ZLyricLy
369ArnoldC170720T010314ZTemporal
017Groovy170719T223342ZGolfIsAG
008V170719T002310ZDJMcMayh
011Perl 6170719T213432ZSean
021QBIC170719T200625Zsteenber
024Cubix170719T183647ZGiuseppe
028PHP170719T173945ZJared Me
006CJam170719T161826Zgeokavel
021Ruby170719T170115Zdaniero
015Dyvil v0.33.0170719T123130ZClashsof
071Common Lisp170719T155502ZCheldon
032Haskell170719T003305Zბიმო
026C170719T152815Zcmaster
016x8616 Machine Code DOS170719T105831ZCody Gra
007Unwanted170719T135929Zfaso
016Befunge98170719T122812Zovs
018Excel170719T124304ZEngineer
025Python 2170719T101053ZAdnan
005Neim170719T011334ZLiefdeWe
00505AB1E170719T114755ZOkx
016><>170719T111005ZTeal pel
023Javascript170719T112109ZSuperSto
025JavaScript170719T111808ZGrax32
028Clojure170719T111244ZJoshua
027Java 8170719T085204ZKevin Cr
017Octave170719T105303ZLuis Men
030Lua170719T105202ZLiam Ham
023Octave170719T103736ZStewie G
005Charcoal170719T103540ZCharlie
005MATL170719T083445ZLuis Men
013Retina170719T095019ZNeil
009Pyth170719T032558ZK Zhang
023Python 3170719T013122ZC McAvoy
008Jelly170719T011319ZDennis
011J170719T005549ZJonah
036Mathematica170719T001323ZZaMoC
011APL170719T001712ZUriel

Pascal, 122 B

This is a function written in Extended Pascal as laid out in ISO standard 10206. In Pascal you cannot read/readLn values of the data type Boolean, only char, integer and real. Therefore a function is used.

type s=packed array[1..32]of char;function f(x:Boolean)=r:s;var i:1..32;begin
for i:=1 to 32 do r[i]:=succ('0',ord(x))end;

Full working example program:

program theRedundantBoolean(output);
    
    const
        duotrigesimalCharMaximum = 32;
    
    type
        duotrigesimalCharDimension = 1‥duotrigesimalCharMaximum;
        { In Pascal, a `packed array[1‥N] of char` is a string data type. }
        duotrigesimalChar = packed array[duotrigesimalCharDimension] of char;
    
    function redundantBitString(
            protected truth: Boolean
        ) = result: duotrigesimalChar;
        var
            charIndex: duotrigesimalCharDimension;
        begin
            for charIndex ≔ 1 to duotrigesimalCharMaximum do
            begin
                result[charIndex] ≔ succ('0', ord(truth))
            end
        end;
    
    begin
        writeLn(redundantBitString(false));
        writeLn(redundantBitString(true))
    end.

Output:

00000000000000000000000000000000
11111111111111111111111111111111

Thunno 2, 4 bytes

Ṙ32ṛ

Attempt This Online!

Input as a Python boolean: True or False.

Explanation

      # Implicit input.
      # The interpreter implicitly converts
      # True and False to 1 and 0, since
      # integers look better than booleans.
Ṙ     # Convert this integer into a string.
 32ṛ  # And pad it with zeros on the left
      # until the length is equal to 32.
      # Implicit output.

Vyxal, 8 5 bytes

S32↳›

Try it Online!

Carrot, 7 bytes

0^*30^#

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

AWK, 20 bytes

{printf"%032d",!!$0}

Try it online! Here, to deal with multiple lines of input, I added \n to the printf modifier.

{                  }  For every input,
 printf"%    ",       prints, without a trailing newline,
         ​0            with leading zeros,
          32d         a 32-digit number,
               !!$0   and this number is the negative of the negative of the input.
                      In awk, only zero(s) and blank lines return false.
                      Anything else return true.
                      See examples in the TIO link above.

Another working code, with 24 bytes: $0=sprintf("%032d",!!$0)

Starry, 82 bytes

     +          + + +  **      +*`      + *  + +.  + +', '.      +  ' `      +.  `
5+                 Push 0
10+1+1+2*0*6+0*    Push 31 (5*(5+1)+1)
0`                 [Label 0]
  6+1*             Subtract 1 from top of stack
  2+1+0.           Print '0'
  2+1+0'           If top is not zero, goto label 0
0,1'               If input is non-zero, goto label 1
  0.6+2'           Print '0', goto label 2
  1`6+0.           [Label 1] print '1'
2`                 [Label 2]

(The number before each symbol represents the number of spaces)

It's pretty straightforward: print 31 zeroes, then print zero if the input is zero, or one if the input is non-zero. Normally, you would need to push a zero to print on the eighth line, but I just used one the zero from the first half of the program. The [Label 2] at the end is important so that the falsey case doesn't fall into the truthy case, and instead jumps to the end.

Try it online!

Julia 0.6, 12 bytes

~x=bin(x,32)

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

Stax, 5 bytes

⌡Ö├⌡→

Run and debug it

Numeric 0 and empty lists are considered falsy. All other values are truthy.

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}

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

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

Try it online!

MY, 10 9 bytes

𝕫BṄiℑpέ←←

Try it online!

Explanation (codepage [with reasoning behind the character]/hex code):

𝕫: 1A - Push an integer from STDIN (lowercase integers)
B: 0B - Push 11 (B is 11 in hex)
Ṅ: 36 - Pop n; push the nth prime, 11th prime is 31 (Ṅ-th)
i: 49 - Pop n; push [1,...,n] (index/iota)
ℑ: 34 - Pop n; push imag(n) (ℑmaginary part, applied to each element, which gives 0 for real numbers)
p: 60 - Pop n; push stringified n (0=>"0" ... 35=>"Z", the b in base upside down)
έ: 56 - Pop n; push n joined by "" (έmpty string)
←: 26 - Pop n; output n with no newline (out←in)
←: 26 - Pop n; output n with no newline (out←in)

I can't believe that this is possible without any two-argument commands whatsoever!

Edit: Saved 1 byte by using primes instead of arithmetic to get 31.

C# (.NET Core), 29 bytes

a=>new string('0',31)+(a?1:0)

OP said 1/0 can be used for truthy/falsey, so can make a an int and it becomes

a=>new string('0',31)+a

C# doesn't really have truthy/falsey though so I will not use this answer.

Try it online!

Japt, 13 11 bytes

?1:0 ¤i31ç0

Explanation:

?1:0 ¤i31ç0
?              // If the input is a truthy, return:
 1             //   1
  :0           //   Else, 0
     ¤         // Convert to a base-2 string
      i        // Insert at index 0:
       31ç0    //   A string filled with 0s, length 31

Saved a byte using a base-2 conversion built-in!

To insert the string of 0s in front of the 1/0, I need to cast the 1 and 0 into a string. The typical way of doing that would be 1s  (3 bytes). But because we're only converting 1s and 0s, I can use the base-2 built-in (2 bytes).


Input can be in the form of an integer or string.

0 and "" are falsy in Japt.

Try it online!

Test suite

Python 3, 33 25 18 15 bytes

Thanks @jurjen-bos for the __mod__ tip.

'%.32d'.__mod__

Try it online!

Braingolf, 10 8 bytes

#␟>[0_]N

Try it online!

is a Unit Separator, ASCII 0x1F, or 31. Can't find the actually character to paste into TIO, so TIO instead uses # 1-, which pushes space (32) and decrements to 31.

Explanation

#␟>[0_]N  Implicit input from commandline args
#␟        Push unit separator (31)
   >       Move top item to bottom of stack
    [..]   Loop, runs 31 times
     0_    Print 0
        N  Boolean conversion, truthy values become 1, falsey values become 0
           Implicit output of top of stack

Java, 40 chars, 40 bytes

This takes string as parameter, which is not correct (falsy/truthy java value is forced by OP to be represented by a boolean).

c->{for(int i=0;++i<32;c=0+c);return c;}

Try It Online!

Valid response : Java, 60 chars, 60 bytes

c->{String k="";for(k+=c?1:0;k.length()<32;k=0+k);return k;}

Try It Online!

I know there is already a Java answer which is shorter than this one, but still :)

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"

Scala, 32 bytes

Sorry but I was forced to do it in 32 bytes >_<

var s=t
for(u<-0 to 30)s="0"+s
s

It's enclosed by a function taking t as parameter (as a string that can be "0" or "1" for resp. falsy or truthy), and s is returned.

Try It Online!

Valid response : Scala, 46 bytes

Same as my java response, I was supposed to take a boolean for the parameter. So :

var s=if(t)"1"else"0"
for(u<-0 to 30)s="0"+s
s

Try It Online!

Brainfuck, 61 60 36 bytes

++++[>++++<-]>[>++>+++<<-]>-[>.<-]>>,.

I'm sure there is a clever way of not moving around so much with the pointers.

I was right. There were. Thanks to @Graviton for giving me the idea!

Next step: Get the values 32 and 48 quicker!

Try it online!

++++        - Increment 1st slot by 4
[           - Loop until 4 becomes 0
    >++++   - Add 4 to 2nd slot
    <-      - Decrement loop
]           - At this point, we point to slot 1 and slot 2 contains 16, which is the Greatest Common Divisor of 48 (value 0 in ASCII) and 32 (final length of answer)
>           - Point to value 16 (slot 2)
[           - Start loop to get our target values 32 and 48
    >++     - Point to slot 3 and multiply 16 by 2 = 32
    >+++    - Point to slot 4 and multiply 16 by 3 = 48
    <<-     - Decrement the loop so that slot 2 becomes 0
]           - We now point slot 2
>-          - Move to slot 3 and remove one so we can spam (output) 31 zeroes
[           - Start outputting until slot 3 is empty
    >.      - Move to slot 4 where our ASCII value for 0 is
    <-      - Decrement the loop so that slot 3 becomes 0
]           - We are now at slot 3 and it is empty.
,.          - We can now gather input from the user and output it.

Was fun for a first Golf!

It has gotten way too late now. What am I even doing

Octave,16 11 bytes

@(x)x(1:32)

Try it online!

A function handle that takes "00000000000000000000000000000001" as truthy and "00000000000000000000000000000000\0" as falsey.

Explanation:

In Octave an array is considered as falsey if at least one of its elements is zero. The 33th element of the second string is a character with the ASCII value of 0 so it can be considered as falsey.

Ly, 20 15 13 bytes

65*1+[0u1-]nu

EDIT: Saved 5 bytes thanks to ovs.
EDIT: Saved another 2 bytes by printing 0 as a number rather than a character.

ArnoldC, 369 bytes

IT'S SHOWTIME
HEY CHRISTMAS TREE A
YOU SET US UP 0
GET YOUR ASS TO MARS A
DO IT NOW
I WANT TO ASK YOU A BUNCH OF QUESTIONS AND I WANT TO HAVE THEM ANSWERED IMMEDIATELY
BECAUSE I'M GOING TO SAY PLEASE A
TALK TO THE HAND "00000000000000000000000000000001"
BULLSHIT
TALK TO THE HAND "00000000000000000000000000000000"
YOU HAVE NO RESPECT FOR LOGIC
YOU HAVE BEEN TERMINATED

Try it online!

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!

V, 8 bytes

32é0Àñl

Try it online!

Explanation:

32é0            " Insert 32 '0's
    Àñ          " Arg1 times...
      <C-a>     "   Increment the number under the cursor
           l    "   Move one char to the right. This will break the loop since there is 
                "   no more room on this line

Perl 6, 11 bytes

'0'x 31~+?*

Try it online!

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.

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:

falsey:

truthy:

both branches reach here:

Loop:

Finally:

PHP, 28 bytes

<?=str_pad($argv[1],32,0,0);

Save as bool.php and run:

$ php bool.php 0
00000000000000000000000000000000
$ php bool.php 1
00000000000000000000000000000001

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.

Ruby, 21 bytes

Yeah, that space needs to be there.. :/

->x{"%032b"%(x ?1:0)}

In Ruby everything except false and nil is truthy; Try it online!

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.

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

Haskell, 37 32 bytes

(('0'<$[1..31])++).show.fromEnum

Try it online!

Thanks @nimi for -5 bytes!

C, 26 bytes

Pretty much the same idea as 1bluestone's solution, but in C it's shorter, and it does work correctly for any integer input:

f(a){printf("%032i",!!a);}

Of course, this includes some implicitly typed variables/functions as all good C-golf answers do... The !! operator is the shortest way to convert any truthy value to 1 in C (via double negation, ! is defined to return either 1 or 0).

Test with:

#include <stdio.h>
f(a){printf("%032i",!!a);}
int main() {
    f(0), printf("\n");
    f(1), printf("\n");
    f(2), printf("\n");
    f(-1), printf("\n");
}

x86-16 Machine Code (DOS), 16 bytes

B4 02          mov  ah,  2
B2 30          mov  dl, '0'
B9 1F 00       mov  cx, 31

            PrintZeros:
CD 21          int  0x21
E2 FC          loop PrintZeros

00 CA          add  dl, bl
CD 21          int  0x21
C3             ret

The above function receives a boolean value (0 == falsey, 1 == truthy) in the BL register (low byte of BX), and prints a "redundant boolean" string to the standard output.

It works by invoking an interrupt (0x21) to make a DOS function call (selected by setting AH to 2) that prints a single character (in DL) to the standard output.

First, the ASCII character '0' is loaded into DL, the counter (CX) is set to 31, and it loops to print the "redundant" bytes. Then, the input boolean value is added to DL (if BL is falsey, adding 0 will leave DL unchanged as ASCII '0'; if BL is truthy, DL will be incremented by one to ASCII '1'), and the final byte is printed.

The function does not return a value.

Pretty decent for a language that doesn't really do strings.


Full Program, 21 bytes

If you want to make it into a full program, only 5 more bytes are required. Instead of passing the input in a register, this reads the input from the arguments passed on the command line when invoking the application. An argument of 0 is interpreted as falsey, as is the complete lack of arguments; an argument greater than 0 is interpreted as truthy.

Simply assemble the following code as a COM program, and then execute it on the command line.

B4 02            mov   ah,  2
B2 30            mov   dl, '0'
B9 1F 00         mov   cx, 31

               PrintZeros:
CD 21            int   0x21
E2 FC            loop  PrintZeros

3A 16 82 00      cmp   dl, BYTE PTR [0x82]  ; compare to 2nd arg, at offset 0x82 in PSP
D6               salc                       ; equivalent to sbb al, al
28 C2            sub   dl, al
CD 21            int   0x21
C3               ret                        ; you can simply 'ret' to end a COM program

Sample Output:

C:\>bool.com
00000000000000000000000000000000
C:\>bool.com 0
00000000000000000000000000000000
C:\>bool.com 1
00000000000000000000000000000001 
C:\>bool.com 2
00000000000000000000000000000001
C:\>bool.com 7
00000000000000000000000000000001

How does it work? Well, it's basically the same thing, until you get down to the CMP instruction. This compares the command-line argument with the value of the DL register (which, you recall, contains an ASCII '0'). In a COM program, the bytes of code are loaded at offset 0x100. Preceding that is the program segment prefix (PSP), which contains information about the state of a DOS program. Specifically, at offset 0x82, you find the first (actually the second, since the first is a space) argument that was specified on the command line when the program was invoked. So, we are just comparing this byte against an ASCII '0'.

The comparison sets the flags, and then the SALC instruction (an undocumented opcode prior to the Pentium, equivalent to sbb al, al, but only 1 byte instead of 2) sets AL to 0 if the two values were equal, or -1 if they were different. It is then obvious that when we subtract AL from DL, this results in either ASCII '0' or '1', as appropriate.

(Note that, somewhat ironically, you will break it if you pass an argument with a leading 0 on the command line, since it looks only at the first character. So 01 will be treated as falsey. :-)

Unwanted, Unnecessary, Opportunistic, 7 bytes

P0M31P*

Pass either 1 or 0 into the register.

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.&!!.@

Excel, 22 20 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.

Python 2, 26 25 bytes

Thanks to Erik the Outgolfer for saving a byte!

Goes for the full program approach:

print+bool(input(31*'0'))

Try it online!

Neim, 6 5 bytes

ᛝΨβ_I

Try it online!

Explanation:

 ᛝ        # Constant 31
  Ψ       # Apply next token to all in list
    β     # Constant 0
     _    # Push each element to stack
      I   # Take Line of input.

Saved a byte thanks to Okx

05AB1E, 5 bytes

¾31׫

Try it online!

><>, 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

Javascript, 23 bytes

a=>'0'.repeat(31)+ +!!a

!!a coerces a into a boolean, which the unary plus turns into an int.

JavaScript, 25 bytes

v=>'0'.repeat(31)+(v?1:0)

31 zeroes and conditionally add a 1 or 0.

Clojure, 28 bytes

#(format "%031d" (if % 1 0))

Truthy is everything but nil and false

Java 8, 31 27 bytes

b->"".format("%032d",b?1:0)

-4 bytes thanks to @OlivierGrégoire.

Try it here.

Octave, 17 bytes

@(n)dec2bin(n,32)

Anonymous function. Works in MATLAB too.

Try it online!

Lua, 30 bytes

("%032d"):format(b and 1 or 0)

Try it online!

Octave, 23 bytes

@(x)[48+[!(1:31),x],'']

Try it online!

This is shorter than all the approaches I tried with printf. I might have missed something though, since I did this on my phone.

Only one byte longer

@(x)[dec2bin(0,31),x+48]

This could be 18 bytes if I could take 1/0 as strings.

@(x)[48+!(1:31),x]

Try it online!

Charcoal, 5 bytes

×0³¹S

Try it online! (Link to the verbose version.)

As Charcoal understand 0 and 1 as True or False, this just prints 31 0s and the input (0 or 1) as 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

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.

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

Python 3, 23 bytes

lambda n:'0'*31+'01'[n]

Try it online!

Jelly, 8 bytes

31”0x⁸ṆṆ

Try it online!

J, 11 bytes

(31#'0'),":

Try it online!

how?

31 zeros
00...000  append     turn the 0 or 1 input into string
(31#'0')    ,       ":

note: in J, booleans are 0 or 1, also known as "the iverson convention," after ken iverson, creator of J and APL

Mathematica, 36 bytes

""<>ToString/@PadLeft[{Boole@#},31]&

Mathematica, 26 bytes

Row@PadLeft[{Boole@#},31]&

Try it online!

APL, 11 bytes

⍕¯32↑1↑1\⍨⊢

How?

1\⍨⊢ - repeat 1 input times - return empty array on falsy value

1↑ - take the first item

¯32↑ - align right with 31 zeros

- format as string