Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help me with this code. I need to convert Binary to Decimal Bimary-Decimal Conversion (50 pts +5 ex.cr.) 2023 For this agsignment you will develop

Help me with this code. I need to convert Binary to Decimal

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Bimary-Decimal Conversion (50 pts +5 ex.cr.) 2023 For this agsignment you will develop a web page which can convert a bimary number to decimal, or a decimal number to binary. You are to accomplish this in jzesscint by coding the specific algorithms shown below for each of these procenses. A starter screen has been provided, as follows: Enter Value to Convert: Direction: To Binary To Decimal Calculations: The Value is: Part A (Decimal to Binary): An algonthm for converting a decimal value into its binary equivalent involves repeated (integer) division by 2 (down to a result of 0 ), collection of the remainders, and reading those remainders 'backwards ( A sample rum is shown below). One approach to this algorithm (that will be shown via lecture) is to accumulate the remainders in an array; and then step through the array backwards to show the regults in proper order. A more elegant approach is to use a recursive algorithm to calculate the remainder, which will allow direct output of the rasults and which does not have any practical limitations on the size of the number being converted. This approach is an extra credit option for the assignment. The validation of the decimal value means checking that it is a positive integer. Direction: To Binary P To Decimal Note on Integer Division: As you can see from the example above, this conversion process requires integer drvision and the modulus operation. The modulus (or' remainder?) operator is the % sign. Integer division, however, poses a slight problem for jawaschith since all numeric variables are intrinsically real numbers. One technique around this problem is to incure that the result of each division by 2 will be an integer - before the division is performed. This particular toick can be accomplished by subtracting the expected remainder before the division. For example, If we need to convert the number 5 to binary, we would do the following: 5%2=15/2=2(integerresult) etc. But iavasarint would produce a reoult of 2.5 for the 512 part, instead of an integer. If, however, we subtract the remainder from the original number before the division by two, we get: 5%2=1(51)/2=2(integerreqult) Part B (Binary to Decimal): A 'standard' algorithm for a binary to decimal comversion evaluates the positional values of the binary digits. For example, the binary value of 1011 is 11 because you bave the following: Binarypowersof2:Positionalvalue:Bimarydigits:2n18=2n2042n122n011 So the value =(18)+(04)+(12)+(11)=11 Likewise, the binary value of 11111101=253 because you have the following: So the value =128+64+32+16+8+4+1=253 In coding the "To Decimal" process remember that you must validate the input as containing only ones and aeros. A sample rm misht appear as follows: Intraidedivinal: var $ = function (id) \{ 1; return document.getelementById(id); window.onload = function () i \$("btnconvert"). onclick = convert; \$("btnclear"). onclick = fnclear; $("txtln") focus () ; 3;1 const isBinary = (value )1 for (let i=0;i=0;i)1 if (value [i]==="1" ) 1 let exp = valueLen 1i; let tmpvalue = Math. pow (2, exp ); decimalNumber t= tmpvalue; Sf"txtcalc") . value =$(" txtcalc") . value + "There is a " + tmpvalue + " in the value 2+ exp + $("txtcalc) value =$(" txtcalc"). value + "There is a " + tmpvalue + "in the value 2 " + ". ln"; alert("Input value may contain caracter(s) other than 0 \& 1 "); else convertmoBinary (val); var decimal =0 var power =0; for (vari= binary.length 1;i>=0;i) powert+; 1 return decimal; ) else ) alert ("Please select a conversion type." ); \}/ /end of convert 85 function annertRvarrav(dval) \& 51F Cloudy J/lend of convert function convertByArray (dval) i varrA=newArray();varr,i,j; \} for (j=rA length 1;j>=0;j){ $("txtout").value=$("txtout")value+rA[j]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Readings In Database Systems

Authors: Michael Stonebraker

2nd Edition

0934613656, 9780934613651

More Books

Students also viewed these Databases questions

Question

6. Effectively perform the managers role in career management.

Answered: 1 week ago

Question

Why is the System Build Process an iterative process?

Answered: 1 week ago