In: Computer Science
Perform double dabble on the following binary (base 2) numbers: Please show your work for full credit. Either digital or hand written is fine.
1. 10011010010
2. 101010
3. 100111010
4. 10101001101
5. 1100100000
For 10pt extra credit - write a program that implements the double dabble algorithm.
Answer
Steps for double dabble
1) Write the given binary number.
2) Starting from the left, double the previous total and add to the current digit.
3) Double your current total and add the next leftmost digit.
4) Continue doubling the current total until the digit end reaches
1) 10011010010 = 1234
solution
0 x 2+1=1
1 x 2+0=2
2 x 2+0=4
4 x 2+1=9
9 x 2+1=19
19 x 2+0=38
38 x 2+1=77
77 x 2+0=154
154 x 2+0=308
308 x 2+1=617
617 x 2+0=1234
2) 101010= 42
solution
0 x 2+1=1
1 x 2+0=2
2 x 2+1=5
5 x 2+0=10
10 x 2+1=21
21 x 2+0=42
3) 100111010 = 314
solution
0 x 2+1=1
1 x 2+0=2
2 x 2+0=4
4 x 2+1=9
9 x 2+1=19
19 x 2+0=39
38 x 2+1=78
77 x 2+0=157
157 x 2 +0 =314
4) 10101001101 = 1357
solution
0 x 2+1=1
1 x 2+0=2
2 x 2+1=5
5 x 2+0=10
10 x 2+1=21
21 x 2+0=42
42 x 2+0=84
84 x 2+1=169
169 x 2+1=339
339 x 2+0=678
678 x 2+1=1357
Code for double dabble in python
note:- Please check the spacing before executing
#function for doubledabble
def doubledabble(bin):
#initilaizing the sum
sum=0
#loop for iterating through the binary digit
for i in bin:
#calculating the sum
sum=(sum*2)+int(i);
#printing the result
print("The decimal digit is:- ",sum)
#main code which take input from user
bin=input("Enter the binary digit\n")
#calling the function
doubledabble(bin)
Screenshots
Input\output