import copy
n, k = map(int, input().split())
a=[]
def bin_to_dec(digit):
dlina=len(digit)
chislo_dec=0
for i in range(0, dlina):
chislo_dec=chislo_dec+int(digit[i])*(2**(dlina-i-1))
return chislo_dec
def dec_to_base(N, base):
if not hasattr(dec_to_base, 'table'):
dec_to_base.table = '0123456789ABCDEF'
x, y = divmod(N, base)
return dec_to_base(x, base) + dec_to_base.table[y] if x else dec_to_base.table[y]
print(2**k) #1
dv=''.join(str(j) for j in str(n))
tr=dec_to_base(n,2)
for i in range(len(tr)):
a.append(int(tr[i]))
print(dv[k-1]) #2
c=copy.copy(a)
b=copy.copy(a)
h=copy.copy(a)
a[-k:]=[0]
for i in range(len(b)-len(a)):
a.append(0)
f=int(''.join(str(j) for j in a))
print(bin_to_dec(str(f))) #3
c[k]=0
g=int(''.join(str(j) for j in c))
print(bin_to_dec(str(g)))
if h[k]==0:
h[k]=1
else:h[k]=0
p=int(''.join(str(j) for j in h))
print(bin_to_dec(str(p)))
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
import copy
n, k = map(int, input().split())
a=[]
def bin_to_dec(digit):
dlina=len(digit)
chislo_dec=0
for i in range(0, dlina):
chislo_dec=chislo_dec+int(digit[i])*(2**(dlina-i-1))
return chislo_dec
def dec_to_base(N, base):
if not hasattr(dec_to_base, 'table'):
dec_to_base.table = '0123456789ABCDEF'
x, y = divmod(N, base)
return dec_to_base(x, base) + dec_to_base.table[y] if x else dec_to_base.table[y]
print(2**k) #1
dv=''.join(str(j) for j in str(n))
tr=dec_to_base(n,2)
for i in range(len(tr)):
a.append(int(tr[i]))
print(dv[k-1]) #2
c=copy.copy(a)
b=copy.copy(a)
h=copy.copy(a)
a[-k:]=[0]
for i in range(len(b)-len(a)):
a.append(0)
f=int(''.join(str(j) for j in a))
print(bin_to_dec(str(f))) #3
c[k]=0
g=int(''.join(str(j) for j in c))
print(bin_to_dec(str(g)))
if h[k]==0:
h[k]=1
else:h[k]=0
p=int(''.join(str(j) for j in h))
print(bin_to_dec(str(p)))
print(2<>1)
print((n&(1<>k)
print(n>>k<print(n & (~(1<print(n ^ (1 << k))