Problem:

Bit Operation I

  Given a non-negative decimal integer $x$, convert it to binary representation $b$ of 32 bits. Then, print the result of the following operations to $b$ respecitvely.

Inversion: change the state of each bit to the opposite state

Logical left shift: shift left by 1

Logical right shift: shift right by 1

Input

  The input is given in the following format.

$x$

Output

  Print the given bits, results of inversion, left shift and right shift in a line respectively.

Constraints

  
$0 \leq x \leq 2^{32} - 1$

Sample Input 1

8

Sample Output 1

00000000000000000000000000001000
11111111111111111111111111110111
00000000000000000000000000010000
00000000000000000000000000000100

Sample Input 2

13

Sample Output 2

00000000000000000000000000001101
11111111111111111111111111110010
00000000000000000000000000011010
00000000000000000000000000000110



Sample input:
8


Sample output:
00000000000000000000000000001000
11111111111111111111111111110111
00000000000000000000000000010000
00000000000000000000000000000100

Submission status: Accepted

Solution code:
def out(n):
    mask = 2**32 -1
    print(format(n&mask,"032b"))

n = int(input())

out(n)
out(~n)
out(n<<1)
out(n>>1)

Submission status: Accepted

Solution code:
x = int(input())
MASK = (1 << 32) - 1
print("{:032b}".format(x))
print("{:032b}".format(~x & MASK))
print("{:032b}".format((x << 1) & MASK))
print("{:032b}".format((x >> 1) & MASK))

Submission status: Accepted

Solution code:
x = int(input())
print(f'{x:032b}')
print(f'{~x & 0xffffffff:032b}')
print(f'{x << 1 & 0xffffffff:032b}')
print(f'{x >> 1:032b}')

Submission status: Accepted

Solution code:
x = int(input())
print("{:032b}".format(x))
print("{:032b}".format(~x & (2**32-1)))
print("{:032b}".format(x << 1 & (2**32-1)))
print("{:032b}".format(x >> 1))

Submission status: Accepted

Solution code:
n=int(input())
m=(1<<32)-1

print("{:032b}".format(n))
print("{:032b}".format(~n&m))
print("{:032b}".format(n<<1&m))
print("{:032b}".format(n>>1))

Submission status: Accepted

Solution code:
def main():
    num = int(input())

    b  = format(num, "032b")
    bi = format( ~num & 0b11111111111111111111111111111111, "032b")
    bl = format(num << 1, "032b")
    br = format(num >> 1, "032b")
    
    print(b)
    print(bi)
    if len(bl) > 32:
        print(bl[-32:])
    else:
        print(bl)

    print(br)

main()

Submission status: Accepted

Solution code:
x = int(input())
s = "{:032b}".format(x)
print(s)
print(s.replace("0","2").replace("1","0").replace("2","1"))
print(s[1:] + "0")
print("0" + s[:-1])

Submission status: Accepted

Solution code:
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

SIZE = 32

POW = [None]*SIZE
POW[0] = 1
for i in range(1,SIZE):
    POW[i] = POW[i-1]*2

x = int(input())
BIT = [0]*SIZE

for i in range(0,SIZE):
    if POW[(SIZE-1)-i] <= x:
        BIT[i] = 1
        x -= POW[(SIZE-1)-i]

#ビット列
for i in range(SIZE):
    print("%d"%(BIT[i]),end="")
print()

#反転
for i in range(SIZE):
    print("%d"%(1-BIT[i]),end="")
print()

#左シフト
for i in range(1,SIZE):
    print("%d"%(BIT[i]),end="")
print("0")

#右シフト
print("0",end="")
for i in range(SIZE-1):
    print("%d"%(BIT[i]),end="")
print()

Submission status: Accepted

Solution code:
n=format(int(input()),'032b')
n_li=list(n)
inversion_n=["1" if n_li[i]=="0"  else "0" for i in range(len(n_li))]
inversion_n= "".join(inversion_n)
left=n[1:len(n)]+"0"
right="0"+n[0:len(n)-1]
print(n)
print(inversion_n)
print(left)
print(right)

Submission status: Accepted

Solution code:
x = int(input())
print( format(x, "032b") )
print( format( ~x & 0b11111111111111111111111111111111, "032b") )
print( format( x<<1, "032b")[-32:] )
print( format( x>>1, "032b") )

Submission status: Accepted

Solution code:
b = int(input())
MAX = (1 << 32) - 1
print("{:032b}".format(b))
print("{:032b}".format(~b & MAX))
print("{:032b}".format((b << 1) & MAX))
print("{:032b}".format((b >> 1) & MAX))

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    x = int(input())
    mask = (1 << 32) - 1
    print(f"{x:032b}")
    print(f"{~x & mask:032b}")
    print(f"{(x << 1) & mask:032b}")
    print(f"{(x >> 1) & mask:032b}")

Submission status: Accepted

Solution code:
x=int(input())
y=format(x,"b").zfill(10)
ly=len(y)
ly=32-ly
pady="0"*ly
print(pady+y)
rev=2**32-1-x
z=format(rev,"b").zfill(10)
lz=len(z)
lz=32-lz
padz="0"*lz
print(padz+z)
left=x*2
if left>=2**32:
    left-=2**32
u=format(left,"b").zfill(10)
lu=len(u)
lu=32-lu
padu="0"*lu
print(padu+u)

right=x//2
v=format(right,"b").zfill(10)
lv=len(v)
lv=32-lv
padv="0"*lv
print(padv+v)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Bitset I - Bit Operation I
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_10_A&lang=jp

"""
x = int(input())
print(f'{x:032b}')
print(f'{x:032b}'.translate(str.maketrans('01', '10')))
print(f'{x<<1:032b}'[-32:])
print(f'{x>>1:032b}')

Submission status: Accepted

Solution code:
x = int(input())

BITMASK = (1 << 32) - 1

print("{:032b}".format(x))
print("{:032b}".format(~x & BITMASK))
print("{:032b}".format((x << 1) & BITMASK))
print("{:032b}".format((x >> 1) & BITMASK))

Submission status: Accepted

Solution code:
n = int(input())
mask = (1<<32)-1
print('{:032b}'.format(n))
print('{:032b}'.format(~n & mask))
print('{:032b}'.format((n<<1)& mask))
print('{:032b}'.format((n>>1)& mask))

Submission status: Accepted

Solution code:
x = int(input())
MASK = (1 << 32) - 1

print("{:032b}".format(x))
print("{:032b}".format(~x & MASK))
print("{:032b}".format((x << 1) & MASK))
print("{:032b}".format((x >> 1) & MASK))

Submission status: Accepted

Solution code:
x=int(input())

b=~x&0b11111111111111111111111111111111
c=(x<<1)&0b11111111111111111111111111111111
d=(x>>1)&0b11111111111111111111111111111111
print(format(x,'032b'))
print(format(b,'032b'))
print(format(c,'032b'))
print(format(d,'032b'))

Submission status: Accepted

Solution code:
x = int(input())

print('{:032b}'.format(x))
print('{:032b}'.format(~x & (2 ** 32 - 1)))
print('{:032b}'.format(x << 1 & (2 ** 32 - 1)))
print('{:032b}'.format(x >> 1))

Submission status: Accepted

Solution code:
n = int(input())
MASK = (1 << 32) -1
print("{:032b}".format(n))
print("{:032b}".format(~n & MASK))
print("{0:032b}".format(n << 1 & MASK))
print("{0:032b}".format(n >> 1 & MASK))

Submission status: Accepted

Solution code:
n = int(input())
print(f'{n:032b}')
print(f'{~n & 0xffffffff:032b}')
print(f'{((n << 1) & 0xffffffff):032b}')
print(f'{n >> 1:032b}')

Submission status: Accepted

Solution code:
x = int(input())

bin_x = format(x, '032b')
bin_x1 = format(~x & 0b11111111111111111111111111111111, '032b')
bin_x2 = format(x << 1 & 0b11111111111111111111111111111111, '032b')
bin_x3 = format(x >> 1 & 0b11111111111111111111111111111111, '032b')

print(bin_x)
print(bin_x1)
print(bin_x2)
print(bin_x3)

Submission status: Accepted

Solution code:
x = int(input())
MASK = (1 << 32) - 1
print("{:032b}".format(x))
print("{:032b}".format(~x & MASK))
print("{:032b}".format((x << 1) & MASK))
print("{:032b}".format((x >> 1) & MASK))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# Bitset 1 - Bit Operation 1


def run():
    n = int(input())
    fmt = "{:032b}"

    print(fmt.format(n))
    print(fmt.format(~n + 2**32))
    print(fmt.format(n << 1 & ~(1 << 32)))
    print(fmt.format(n >> 1))


if __name__ == '__main__':
    run()

Submission status: Accepted

Solution code:
n = int(input())
print(bin(n)[2:].zfill(32))
print(bin(2**32-n-1)[2:].zfill(32))
a = bin(n<<1)[2:].zfill(32)
print(a[-32:])
print(bin(n>>1)[2:].zfill(32))