xxxxxxxxxx
==== Convert binary to decimal in Python ======
a = '11001100' # input a binary
b = int(a,2) # base 2 to base 10
print(b,type(b)) # 204 <class 'int'>
xxxxxxxxxx
def to_int(binary):
total = 0
power = 0
for i in binary[::-1]:
if int(i) == 1:
total += pow(2, power)
power += 1
return total
xxxxxxxxxx
binary_str = input("Enter a Binary number to convert it to Decimal :")
decimal_num = int(binary_str, 2)
print(decimal_num)
xxxxxxxxxx
def binary2int(binary):
int_val, i, n = 0, 0, 0
while(binary != 0):
a = binary % 10
int_val = int_val + a * pow(2, i)
binary = binary//10
i += 1
print(int_val)
binary2int(101)
xxxxxxxxxx
binary_num = input("Enter a binary number: ")
decimal_num = int(binary_num, 2)
print("Decimal equivalent:", decimal_num)
xxxxxxxxxx
#instead of using this
client.completions.create(
model="gpt-35-turbo-16k",
prompt="This is a prompt")
#use the following code :
client.chat.completions.create(
model="gpt-4",
messages = [{"role":"system", "content":"this is a prompt"}])