From 33ba04e07eba0d9484b74c7c7d8e9d069290c0cf Mon Sep 17 00:00:00 2001 From: sravanthi Reddy Date: Wed, 7 Apr 2021 13:11:01 +0530 Subject: [PATCH 01/20] color correction --- experiment/simulation/js/bitwisefbit.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/experiment/simulation/js/bitwisefbit.js b/experiment/simulation/js/bitwisefbit.js index 3565cad..2c051d0 100644 --- a/experiment/simulation/js/bitwisefbit.js +++ b/experiment/simulation/js/bitwisefbit.js @@ -41,8 +41,8 @@ function addoverflow() newcell = rowvar.insertCell(-1) if(resultarray[i]==0){ newcell.innerHTML="overflow"; - newcell.style.fontSize = "small" ; - newcell.style.color="rgb(164, 198, 82)"; + newcell.style.fontSize = "x-small" ; + newcell.style.backgroundColor="rgb(164, 198, 82)"; newcell.style.fontWeight='bold'; } visitedarray[i]=1 From cc0d40f10f7735605dd1228a0e1a4f3bca9d2423 Mon Sep 17 00:00:00 2001 From: Pranjal Jain <56213303+rnajain652@users.noreply.github.com> Date: Wed, 7 Apr 2021 20:30:40 +0530 Subject: [PATCH 02/20] Update bitwisefbit.js --- experiment/simulation/js/bitwisefbit.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/experiment/simulation/js/bitwisefbit.js b/experiment/simulation/js/bitwisefbit.js index 2c051d0..542895a 100644 --- a/experiment/simulation/js/bitwisefbit.js +++ b/experiment/simulation/js/bitwisefbit.js @@ -111,11 +111,7 @@ function addfunc() { ar1 = [] ar2 = [] - for (let i=0;i Date: Wed, 7 Apr 2021 20:31:03 +0530 Subject: [PATCH 03/20] Update bitwise.js --- experiment/simulation/js/bitwise.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/experiment/simulation/js/bitwise.js b/experiment/simulation/js/bitwise.js index b5bd55d..2f00224 100644 --- a/experiment/simulation/js/bitwise.js +++ b/experiment/simulation/js/bitwise.js @@ -120,11 +120,7 @@ function addfunc() { ar1 = [] ar2 = [] - for (let i=0;i Date: Sat, 10 Apr 2021 16:07:56 +0530 Subject: [PATCH 04/20] Update pretest.json --- experiment/pretest.json | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/experiment/pretest.json b/experiment/pretest.json index 6edba59..5fb1202 100644 --- a/experiment/pretest.json +++ b/experiment/pretest.json @@ -1,18 +1,20 @@ [ -{"question":"This is a Sample Question 1?", +{"Sign magnitude is a very simple representation of ?", "answers":{ - "a":"answer1", - "b":"answer2", - "c":"answer3", - "d":"answer4" + "a":"Positive number", + "b":"Infinity", + "c":"Zero", + "d":"Negative numbers" }, +"correctAnswer":"d"}, +{ "correctAnswer":"a"}, -{"question":"This is a Sample Question 2?", +"question":"Which method of representation has two representations for ‘0’ ?", "answers":{ - "a":"answer1", - "b":"answer2", - "c":"answer3", - "d":"answer4" + "a":"Sign-magnitude", + "b":"1’s compliment", + "c":"2's complement form", + "d":"None of the above" }, -"correctAnswer":"c"} +"correctAnswer":"a"} ] From aca97c03d3662d4c8f70ae297c849c605c1f6350 Mon Sep 17 00:00:00 2001 From: sravanthi657 <71112579+sravanthi657@users.noreply.github.com> Date: Sat, 10 Apr 2021 16:08:32 +0530 Subject: [PATCH 05/20] Update posttest.json --- experiment/posttest.json | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/experiment/posttest.json b/experiment/posttest.json index 6edba59..82e5eeb 100644 --- a/experiment/posttest.json +++ b/experiment/posttest.json @@ -1,18 +1,18 @@ [ -{"question":"This is a Sample Question 1?", +{"question":"The final addition sum of the numbers, 0110 & 0110 is ?", "answers":{ - "a":"answer1", - "b":"answer2", - "c":"answer3", - "d":"answer4" + "a":"1101", + "b":"1001", + "c":"1111", + "d":"1010" }, "correctAnswer":"a"}, -{"question":"This is a Sample Question 2?", +{"question":"Which of the following cases leads to the overflow condition in addition using 2’s complement?", "answers":{ - "a":"answer1", - "b":"answer2", - "c":"answer3", - "d":"answer4" + "a":"Addition of two positive numbers, which results in sum ≥ 2^(n-1)", + "b":"Addition of two positive numbers, which results in sum < 2^(n–1)", + "c":"Addition of two negative numbers, |sum| ≤ 2^(n–1)", + "d":"Addition of two negative numbers, |sum| > 2^(n–1)" }, -"correctAnswer":"c"} +"correctAnswer":"a"} ] From bdc907ead16f826dc5ac322965cfd7e21742762e Mon Sep 17 00:00:00 2001 From: sravanthi657 <71112579+sravanthi657@users.noreply.github.com> Date: Sat, 10 Apr 2021 19:24:06 +0530 Subject: [PATCH 06/20] Create pretest.json --- experiment/pretest.json | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/experiment/pretest.json b/experiment/pretest.json index 5fb1202..ba6dc27 100644 --- a/experiment/pretest.json +++ b/experiment/pretest.json @@ -1,5 +1,5 @@ [ -{"Sign magnitude is a very simple representation of ?", +{"question":"Sign magnitude is a very simple representation of ?", "answers":{ "a":"Positive number", "b":"Infinity", @@ -7,9 +7,8 @@ "d":"Negative numbers" }, "correctAnswer":"d"}, -{ -"correctAnswer":"a"}, -"question":"Which method of representation has two representations for ‘0’ ?", + +{"question":"Which method of representation has two representations for ‘0’ ?", "answers":{ "a":"Sign-magnitude", "b":"1’s compliment", From aa75c87f1d3199e542e1953043ca2d731e360fc3 Mon Sep 17 00:00:00 2001 From: sravanthi Reddy Date: Tue, 20 Apr 2021 20:26:53 +0530 Subject: [PATCH 07/20] moslty follwed guidelines --- .../simulation/css/{co1.css => main.css} | 0 experiment/simulation/html/CO1_5-bit.html | 2 +- experiment/simulation/index.html | 4 +- experiment/simulation/js/bitwise.js | 470 ------------------ experiment/simulation/js/bitwisefbit.js | 372 +++++++------- experiment/simulation/js/main.js | 463 +++++++++++++++++ 6 files changed, 649 insertions(+), 662 deletions(-) rename experiment/simulation/css/{co1.css => main.css} (100%) delete mode 100644 experiment/simulation/js/bitwise.js create mode 100644 experiment/simulation/js/main.js diff --git a/experiment/simulation/css/co1.css b/experiment/simulation/css/main.css similarity index 100% rename from experiment/simulation/css/co1.css rename to experiment/simulation/css/main.css diff --git a/experiment/simulation/html/CO1_5-bit.html b/experiment/simulation/html/CO1_5-bit.html index 02d5855..9cc0624 100644 --- a/experiment/simulation/html/CO1_5-bit.html +++ b/experiment/simulation/html/CO1_5-bit.html @@ -4,7 +4,7 @@ - + Stimulation | Integer Arithmetic|Computer Organization diff --git a/experiment/simulation/index.html b/experiment/simulation/index.html index 5988f1c..b8e5fc7 100644 --- a/experiment/simulation/index.html +++ b/experiment/simulation/index.html @@ -6,7 +6,7 @@ Representation of Integers and their Arithmetic - +
@@ -220,6 +220,6 @@

Results

- + \ No newline at end of file diff --git a/experiment/simulation/js/bitwise.js b/experiment/simulation/js/bitwise.js deleted file mode 100644 index b5bd55d..0000000 --- a/experiment/simulation/js/bitwise.js +++ /dev/null @@ -1,470 +0,0 @@ -let messages=[ -"Hover over the 4-bit table and Select any two rows to add", -"Results are highlighted green and overflow is displayed in result table\nClick on 5-bit table to switch", -"Click on reset to clear and restart anytime", -] -mat = [] -temp = [] -tobeadded = [] -selectedrow = [] -coloredidx = [] -resultarray = [0,0,0,0,0] -visitedarray = [0,0,0,0,0] -resultarrayname = ['rowbinar','row2s','row1s','rowunsigned','rowsigned'] -vis = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] -sameelemflag = 0 -let glob = 0 -let flag = 0 -let afteradd = 0 -let message = messages[0]; -document.getElementById("message").innerHTML = message; -function active_switch(switch_from) -{ - if(switch_from=="five-switch") - { - console.log('why is this"what is this?') - $(document.getElementById(switch_from)).hide() - $(document.getElementById('four-switch')).show() - } - else - { - $(document.getElementById(switch_from)).hide() - $(document.getElementById('five-switch')).show() - } - -} - -function addoverflow() -{ - for (var i=0;i<5;i++) - { - console.log(resultarray[i]) - } - console.log("inside addrow id=") - for (var i=0;i<5;i++) - { - rowvar = document.getElementById(resultarrayname[i]) - newcell = rowvar.insertCell(-1) - if(resultarray[i]==0){ - newcell.innerHTML="overflow"; - newcell.style.fontSize = "x-small"; - newcell.style.backgroundColor="rgb(164, 198, 82)"; - newcell.style.fontWeight ='bolder'; - } - visitedarray[i]=1 - } - -} -function deleterow() -{ - for (var i=0;i<5;i++) - { - if (visitedarray[i]==1) - { - document.getElementById(resultarrayname[i]).deleteCell(-1) - visitedarray[i]=0 - } - } - -} -function mouseOver(indx) -{ - if(vis[parseInt(indx)]==0) - { - document.getElementById(indx).style.backgroundColor='#c3d8ed' - } -} -function mouseOut(indx) -{ - if (vis[parseInt(indx)]==0) - { - document.getElementById(indx).style.backgroundColor='transparent' - } -} -function reset() -{ - vis = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] - mat = [] - temp = [] - tobeadded = [] - document.getElementById('binar').innerHTML='' - document.getElementById('2s').innerHTML='' - document.getElementById('1s').innerHTML='' - document.getElementById('unsigned').innerHTML='' - document.getElementById('signed').innerHTML='' - if (glob!=0||afteradd==1) - { - afteradd=0 - } - glob=0 - for (var i=0;i=0;i--) - { - if (a[i]==='1' && b[i]==='1') - { - if (carry==='1') - { - c.push('1') - } - else - { - c.push('0') - carry = '1' - } - } - else if ((a[i]==='0' && b[i]==='1') ||(a[i]==='1' && b[i]==='0') ) - { - if (carry==='1') - { - c.push('0') - } - else - { - c.push('1') - } - } - else - { - if (carry === '1') - { - carry='0' - c.push('1') - } - else - { - c.push('0') - } - } - - } - if (carry==='1') - { - c.push('1') - } - c.reverse() - str1 = "" - for(let i=0;i= 0; i--) - { - if(result[i] == '1') - { - unsignval += Math.pow(2,result.length - 1 - i) - } - } - return unsignval - } - document.getElementById('signed').innerHTML = signed(str1) - function signed(result) - { - signval = 0 - sign = "" - if(a[0] == b[0] && result[0] != a[0]) - { - signval = unsigned(str1) - } - else - { - if (result[result.length - 1] == '1') - { - signval = 1 - } - for(i = result.length - 2; i >= 0; i--) - { - if(result[i] == '1' && i != 0) - { - signval += Math.pow(2,result.length - 1 - i) - } - if(i == 0) - { - if(result[i] == '1') - { - sign = "-" - } - } - } - if(signval == 0) - { - sign = "" - } - } - signval = sign + signval - - return signval - } - - onescomplement(str1) - function onescomplement(result) - { - complement1 = "" - valcomplement1 = 0 - if(a[0] == b[0] && result[0] != a[0]) - { - console.log("hi there i am here") - valcomplement1 = unsigned(str1) - valcomplement2 = valcomplement1 - } - else - { - if(result[0] == '0') - { - valcomplement1 = unsigned(result) - valcomplement2 = valcomplement1 - } - else - { - for (i = 0; i < result.length; i++) - { - if(result[i] == '0') - { - complement1+="1" - } - else - { - complement1+="0" - } - - } - valcomplement1 = "-" + unsigned(complement1) - if(unsigned(complement1) == 0) - { - valcomplement1 = 0 - } - twoscomplement(complement1) - } - } - - } - function setgreencolor(idx,strin) - { - flag = 0 - for (var i=0;i<16;i++) - { - if(mat[i][idx]==strin) - { - var index = (100*(i+1)+idx) - coloredidx.push(index) - document.getElementById(index).style.backgroundColor='rgb(164, 198, 82)' - document.getElementById(index).style.color='white' - flag = 1 - break - } - } - return flag - } - function twoscomplement(result) - { - complement = [] - complement2 = "" - valcomplement2 = 0 - carry = 1 - for (i = result.length - 1; i >= 0; i--) - { - if (carry == 0) - { - if(result[i] == "0") - { - complement.push("0") - carry = 0 - } - else - { - complement.push("1") - carry = 0 - } - } - else if(carry == 1) - { - if(result[i] == "0") - { - complement.push("1") - carry = 0 - } - else - { - complement.push("0") - carry = 1 - } - } - if(i == 0) - { complement.reverse() - for(j = 0; j < complement.length; j++) - { - complement2 += complement[j] - } - if(carry == 1) - { - complement2 = "1" + complement2 - } - } - } - valcomplement2 = "-" + unsigned(complement2) - } - document.getElementById('binar').innerHTML = str1 - document.getElementById('2s').innerHTML = valcomplement2 - document.getElementById('1s').innerHTML = valcomplement1 - resultarray[0]=setgreencolor(1,document.getElementById('binar').innerHTML) - resultarray[1]=setgreencolor(2,document.getElementById('2s').innerHTML) - resultarray[2]=setgreencolor(3,document.getElementById('1s').innerHTML) - resultarray[3]=setgreencolor(4,document.getElementById('unsigned').innerHTML) - resultarray[4]=setgreencolor(5,document.getElementById('signed').innerHTML) - addoverflow(); - let message = messages[1]; - document.getElementById("message").innerHTML = message; - -} \ No newline at end of file diff --git a/experiment/simulation/js/bitwisefbit.js b/experiment/simulation/js/bitwisefbit.js index 2c051d0..8209e96 100644 --- a/experiment/simulation/js/bitwisefbit.js +++ b/experiment/simulation/js/bitwisefbit.js @@ -1,27 +1,27 @@ -let messages=[ +const messages=[ "Hover over the 5-bit table and Select any two rows to add", "Results are highlighted green and overflow is displayed in result table\nClick on 4-bit table to switch", "Click on reset to clear and restart anytime", ] -mat = [] -temp = [] -tobeadded = [] -selectedrow = [] -coloredidx = [] -resultarray = [0,0,0,0,0] -visitedarray = [0,0,0,0,0] -resultarrayname = ['rowbinar','row2s','row1s','rowunsigned','rowsigned'] -vis = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] -sameelemflag = 0 -let glob = 0 -let flag = 0 +let mat = []; +let temp = []; +let tobeadded = []; +let selectedrow = []; +let coloredidx = []; +let resultarray = [0,0,0,0,0]; +let visitedarray = [0,0,0,0,0] ; +let resultarrayname = ['rowbinar','row2s','row1s','rowunsigned','rowsigned']; +let vis = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]; +let sameelemflag = 0; +let glob = 0; +let flag = 0; let message = messages[0]; document.getElementById("message").innerHTML = message; var width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; -console.log("screen width is ") -console.log(width) +console.log("screen width is "); +console.log(width); if (width < 350) { console.log("hi") document.getElementById('ab').innerHTML = "Un sig ned"; @@ -32,20 +32,20 @@ function addoverflow() { for (var i=0;i<5;i++) { - console.log(resultarray[i]) + console.log(resultarray[i]); } console.log("inside addrow id=") for (var i=0;i<5;i++) { - rowvar = document.getElementById(resultarrayname[i]) - newcell = rowvar.insertCell(-1) - if(resultarray[i]==0){ + rowvar = document.getElementById(resultarrayname[i]); + newcell = rowvar.insertCell(-1); + if(resultarray[i]===0){ newcell.innerHTML="overflow"; newcell.style.fontSize = "x-small" ; newcell.style.backgroundColor="rgb(164, 198, 82)"; newcell.style.fontWeight='bold'; } - visitedarray[i]=1 + visitedarray[i]=1 ; } } @@ -53,52 +53,52 @@ function deleterow() { for (var i=0;i<5;i++) { - if (visitedarray[i]==1) + if (visitedarray[i]===1) { - document.getElementById(resultarrayname[i]).deleteCell(-1) - visitedarray[i]=0 + document.getElementById(resultarrayname[i]).deleteCell(-1); + visitedarray[i]=0; } } } function mouseOver(indx) { - if(vis[parseInt(indx)]==0) + if(vis[parseInt(indx)]===0) { - document.getElementById(indx).style.color='' + document.getElementById(indx).style.color=''; } } function mouseOut(indx) { - if (vis[parseInt(indx)]==0) + if (vis[parseInt(indx)]===0) { - document.getElementById(indx).style.backgroundColor='transparent' + document.getElementById(indx).style.backgroundColor='transparent'; } } function reset() { - vis = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] - mat = [] - temp = [] - tobeadded = [] - document.getElementById('binar').innerHTML='' - document.getElementById('2s').innerHTML='' - document.getElementById('1s').innerHTML='' - document.getElementById('unsigned').innerHTML='' - document.getElementById('signed').innerHTML='' - glob=0 + vis = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]; + mat = []; + temp = []; + tobeadded = []; + document.getElementById('binar').innerHTML=''; + document.getElementById('2s').innerHTML=''; + document.getElementById('1s').innerHTML=''; + document.getElementById('unsigned').innerHTML=''; + document.getElementById('signed').innerHTML=''; + glob=0; for (var i=0;i=0;i--) { if (a[i]==='1' && b[i]==='1') { if (carry==='1') { - c.push('1') + c.push('1'); } else { - c.push('0') - carry = '1' + c.push('0'); + carry = '1'; } } else if ((a[i]==='0' && b[i]==='1') ||(a[i]==='1' && b[i]==='0') ) { if (carry==='1') { - c.push('0') + c.push('0'); } else { - c.push('1') + c.push('1'); } } else { if (carry === '1') { - carry='0' - c.push('1') + carry='0'; + c.push('1'); } else { - c.push('0') + c.push('0'); } } } if (carry==='1') { - c.push('1') + c.push('1'); } - c.reverse() - str1 = "" + c.reverse(); + str1 = ""; for(let i=0;i= 0; i--) { - if(result[i] == '1') + if(result[i] === '1') { - unsignval += Math.pow(2,result.length - 1 - i) + unsignval += Math.pow(2,result.length - 1 - i); } } - return unsignval + return unsignval; } - document.getElementById('signed').innerHTML = signed(str1) + document.getElementById('signed').innerHTML = signed(str1); function signed(result) { - signval = 0 - sign = "" - if(a[0] == b[0] && result[0] != a[0]) + signval = 0; + sign = ""; + if(a[0] === b[0] && result[0] != a[0]) { - signval = unsigned(str1) + signval = unsigned(str1) ; } else { - if (result[result.length - 1] == '1') + if (result[result.length - 1] === '1') { - signval = 1 + signval = 1; } for(i = result.length - 2; i >= 0; i--) { - if(result[i] == '1' && i != 0) + if(result[i] === '1' && i != 0) { - signval += Math.pow(2,result.length - 1 - i) + signval += Math.pow(2,result.length - 1 - i); } - if(i == 0) + if(i === 0) { - if(result[i] == '1') + if(result[i] === '1') { - sign = "-" + sign = "-"; } } } - if(signval == 0) + if(signval === 0) { - sign = "" + sign = ""; } } - signval = sign + signval - return signval + signval = sign + signval; + return signval; } - onescomplement(str1) + onescomplement(str1); function onescomplement(result) { - complement1 = "" - valcomplement1 = 0 - if(a[0] == b[0] && result[0] != a[0]) + complement1 = ""; + valcomplement1 = 0; + if(a[0] === b[0] && result[0] != a[0]) { - console.log("hi there i am here") - valcomplement1 = unsigned(str1) - valcomplement2 = valcomplement1 + console.log("hi there i am here"); + valcomplement1 = unsigned(str1) ; + valcomplement2 = valcomplement1; } else { - if(result[0] == '0') + if(result[0] === '0') { - valcomplement1 = unsigned(result) - valcomplement2 = valcomplement1 + valcomplement1 = unsigned(result); + valcomplement2 = valcomplement1; } else { for (i = 0; i < result.length; i++) { - if(result[i] == '0') + if(result[i] === '0') { - complement1+="1" + complement1+="1"; } else { - complement1+="0" + complement1+="0"; } } - valcomplement1 = "-" + unsigned(complement1) - if(unsigned(complement1) == 0) + valcomplement1 = "-" + unsigned(complement1); + if(unsigned(complement1) === 0) { - valcomplement1 = 0 + valcomplement1 = 0; } - twoscomplement(complement1) + twoscomplement(complement1); } } } function setgreencolor(idx,strin) { - flag = 0 + flag = 0; for (var i=0;i<32;i++) { - if(mat[i][idx]==strin) + if(mat[i][idx]===strin) { - var index = (100*(i+1)+idx) - coloredidx.push(index) + var index = (100*(i+1)+idx); + coloredidx.push(index); document.getElementById(index).style.backgroundColor='rgb(164, 198, 82)'; - document.getElementById(index).style.color='white' + document.getElementById(index).style.color='white'; - flag = 1 - break + flag = 1; + break; } } - return flag + return flag; } function twoscomplement(result) { - complement = [] - complement2 = "" - valcomplement2 = 0 - carry = 1 + complement = []; + complement2 = ""; + valcomplement2 = 0; + carry = 1; for (i = result.length - 1; i >= 0; i--) { - if (carry == 0) + if (carry === 0) { - if(result[i] == "0") + if(result[i] === "0") { - complement.push("0") - carry = 0 + complement.push("0"); + carry = 0; } else { - complement.push("1") - carry = 0 + complement.push("1"); + carry = 0; } } - else if(carry == 1) + else if(carry === 1) { - if(result[i] == "0") + if(result[i] === "0") { - complement.push("1") - carry = 0 + complement.push("1"); + carry = 0; } else { - complement.push("0") - carry = 1 + complement.push("0"); + carry = 1; } } - if(i == 0) + if(i === 0) { complement.reverse() for(j = 0; j < complement.length; j++) { - complement2 += complement[j] + complement2 += complement[j]; } - if(carry == 1) + if(carry === 1) { - complement2 = "1" + complement2 + complement2 = "1" + complement2; } } } - valcomplement2 = "-" + unsigned(complement2) + valcomplement2 = "-" + unsigned(complement2); } - console.log("inside add part") - document.getElementById('binar').innerHTML = str1 - document.getElementById('2s').innerHTML = valcomplement2 - document.getElementById('1s').innerHTML = valcomplement1 - resultarray[0]=setgreencolor(1,document.getElementById('binar').innerHTML) - resultarray[1]=setgreencolor(2,document.getElementById('2s').innerHTML) - resultarray[2]=setgreencolor(3,document.getElementById('1s').innerHTML) - resultarray[3]=setgreencolor(4,document.getElementById('unsigned').innerHTML) - resultarray[4]=setgreencolor(5,document.getElementById('signed').innerHTML) + console.log("inside add part"); + document.getElementById('binar').innerHTML = str1; + document.getElementById('2s').innerHTML = valcomplement2; + document.getElementById('1s').innerHTML = valcomplement1; + resultarray[0]=setgreencolor(1,document.getElementById('binar').innerHTML); + resultarray[1]=setgreencolor(2,document.getElementById('2s').innerHTML); + resultarray[2]=setgreencolor(3,document.getElementById('1s').innerHTML); + resultarray[3]=setgreencolor(4,document.getElementById('unsigned').innerHTML); + resultarray[4]=setgreencolor(5,document.getElementById('signed').innerHTML); addoverflow(); let message = messages[1]; document.getElementById("message").innerHTML = message; diff --git a/experiment/simulation/js/main.js b/experiment/simulation/js/main.js new file mode 100644 index 0000000..fe3056a --- /dev/null +++ b/experiment/simulation/js/main.js @@ -0,0 +1,463 @@ +let messages=[ +"Hover over the 4-bit table and Select any two rows to add", +"Results are highlighted green and overflow is displayed in result table\nClick on 5-bit table to switch", +"Click on reset to clear and restart anytime", +]; +let mat = []; +let temp = []; +let tobeadded = []; +let selectedrow = []; +let coloredidx = []; +let resultarray = [0,0,0,0,0]; +let visitedarray = [0,0,0,0,0]; +let resultarrayname = ['rowbinar','row2s','row1s','rowunsigned','rowsigned']; +vis = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]; +sameelemflag = 0; +let glob = 0; +let flag = 0; +let afteradd = 0; +let message = messages[0]; +document.getElementById("message").innerHTML = message; +function active_switch(switch_from) +{ + if(switch_from==="five-switch") + { + console.log('why is this"what is this?'); + $(document.getElementById(switch_from)).hide(); + $(document.getElementById('four-switch')).show(); + } + else + { + $(document.getElementById(switch_from)).hide(); + $(document.getElementById('five-switch')).show(); + } + +} + +function addoverflow() +{ + for (var i=0;i<5;i++) + { + console.log(resultarray[i]); + } + console.log("inside addrow id=") + for (var i=0;i<5;i++) + { + rowvar = document.getElementById(resultarrayname[i]); + newcell = rowvar.insertCell(-1); + if(resultarray[i]===0){ + newcell.innerHTML="overflow"; + newcell.style.fontSize = "x-small"; + newcell.style.backgroundColor="rgb(164, 198, 82)"; + newcell.style.fontWeight ='bolder'; + } + visitedarray[i]=1; + } + +} +function deleterow() +{ + for (var i=0;i<5;i++) + { + if (visitedarray[i]===1) + { + document.getElementById(resultarrayname[i]).deleteCell(-1); + visitedarray[i]=0; + } + } + +} +function mouseOver(indx) +{ + if(vis[parseInt(indx)]===0) + { + document.getElementById(indx).style.backgroundColor='#c3d8ed'; + } +} +function mouseOut(indx) +{ + if (vis[parseInt(indx)]===0) + { + document.getElementById(indx).style.backgroundColor='transparent'; + } +} +function reset() +{ + vis = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]; + mat = []; + temp = []; + tobeadded = []; + document.getElementById('binar').innerHTML=''; + document.getElementById('2s').innerHTML=''; + document.getElementById('1s').innerHTML=''; + document.getElementById('unsigned').innerHTML=''; + document.getElementById('signed').innerHTML=''; + if (glob!=0||afteradd===1) + { + afteradd=0; + } + glob=0; + for (var i=0;i=0;i--) + { + if (a[i]==='1' && b[i]==='1') + { + if (carry==='1') + { + c.push('1'); + } + else + { + c.push('0'); + carry = '1'; + } + } + else if ((a[i]==='0' && b[i]==='1') ||(a[i]==='1' && b[i]==='0') ) + { + if (carry==='1') + { + c.push('0'); + } + else + { + c.push('1'); + } + } + else + { + if (carry === '1') + { + carry='0'; + c.push('1'); + } + else + { + c.push('0'); + } + } + + } + if (carry==='1') + { + c.push('1'); + } + c.reverse(); + str1 = ""; + for(let i=0;i= 0; i--) + { + if(result[i] === '1') + { + unsignval += Math.pow(2,result.length - 1 - i); + } + } + return unsignval; + } + document.getElementById('signed').innerHTML = signed(str1); + function signed(result) + { + signval = 0; + sign = ""; + if(a[0] === b[0] && result[0] != a[0]) + { + signval = unsigned(str1) ; + } + else + { + if (result[result.length - 1] === '1') + { + signval = 1; + } + for(i = result.length - 2; i >= 0; i--) + { + if(result[i] === '1' && i != 0) + { + signval += Math.pow(2,result.length - 1 - i); + } + if(i === 0) + { + if(result[i] === '1') + { + sign = "-"; + } + } + } + if(signval === 0) + { + sign = ""; + } + } + signval = sign + signval; + + return signval; + } + + onescomplement(str1); + function onescomplement(result) + { + complement1 = ""; + valcomplement1 = 0; + if(a[0] === b[0] && result[0] != a[0]) + { + console.log("hi there i am here"); + valcomplement1 = unsigned(str1); + valcomplement2 = valcomplement1; + } + else + { + if(result[0] === '0') + { + valcomplement1 = unsigned(result); + valcomplement2 = valcomplement1; + } + else + { + for (i = 0; i < result.length; i++) + { + if(result[i] === '0') + { + complement1+="1"; + } + else + { + complement1+="0"; + } + + } + valcomplement1 = "-" + unsigned(complement1); + if(unsigned(complement1) === 0) + { + valcomplement1 = 0; + } + twoscomplement(complement1); + } + } + + } + function setgreencolor(idx,strin) + { + flag = 0; + for (var i=0;i<16;i++) + { + if(mat[i][idx]===strin) + { + var index = (100*(i+1)+idx); + coloredidx.push(index); + document.getElementById(index).style.backgroundColor='rgb(164, 198, 82)'; + document.getElementById(index).style.color='white'; + flag = 1; + break; + } + } + return flag; + } + function twoscomplement(result) + { + complement = []; + complement2 = ""; + valcomplement2 = 0; + carry = 1; + for (i = result.length - 1; i >= 0; i--) + { + if (carry === 0) + { + if(result[i] === "0") + { + complement.push("0"); + carry = 0; + } + else + { + complement.push("1"); + carry = 0; + } + } + else if(carry === 1) + { + if(result[i] === "0") + { + complement.push("1"); + carry = 0; + } + else + { + complement.push("0"); + carry = 1; + } + } + if(i === 0) + { complement.reverse() + for(j = 0; j < complement.length; j++) + { + complement2 += complement[j]; + } + if(carry === 1) + { + complement2 = "1" + complement2; + } + } + } + valcomplement2 = "-" + unsigned(complement2); + } + document.getElementById('binar').innerHTML = str1; + document.getElementById('2s').innerHTML = valcomplement2; + document.getElementById('1s').innerHTML = valcomplement1; + resultarray[0]=setgreencolor(1,document.getElementById('binar').innerHTML); + resultarray[1]=setgreencolor(2,document.getElementById('2s').innerHTML); + resultarray[2]=setgreencolor(3,document.getElementById('1s').innerHTML); + resultarray[3]=setgreencolor(4,document.getElementById('unsigned').innerHTML); + resultarray[4]=setgreencolor(5,document.getElementById('signed').innerHTML); + addoverflow(); + let message = messages[1]; + document.getElementById("message").innerHTML = message; + +} \ No newline at end of file From 1dd80c2f49cffca3774315882c65b726a47fbda8 Mon Sep 17 00:00:00 2001 From: sravanthi Reddy Date: Mon, 26 Apr 2021 00:34:07 +0530 Subject: [PATCH 08/20] camelcase variables --- experiment/simulation/css/main.css | 18 -- experiment/simulation/html/CO1_5-bit.html | 4 +- experiment/simulation/js/bitwisefbit.js | 196 ++++++++++---------- experiment/simulation/js/main.js | 212 +++++++++++----------- 4 files changed, 205 insertions(+), 225 deletions(-) diff --git a/experiment/simulation/css/main.css b/experiment/simulation/css/main.css index f0c27ca..a8d57b7 100644 --- a/experiment/simulation/css/main.css +++ b/experiment/simulation/css/main.css @@ -172,24 +172,6 @@ div.operations button { } } -@media screen and (max-width: 768px) { - .message { - font-size: 2vh; - margin-left: 10px; - margin-right: 10px; - } - #main-heading { - padding-top: 10px; - font-size: 3vh; - } - #result-heading { - font-size: 6vw; - } - .btn { - font-size: 70%; - } -} - @media screen and (max-width: 380px) { .message { font-size: 5vw; diff --git a/experiment/simulation/html/CO1_5-bit.html b/experiment/simulation/html/CO1_5-bit.html index 1f2e0f9..528244c 100644 --- a/experiment/simulation/html/CO1_5-bit.html +++ b/experiment/simulation/html/CO1_5-bit.html @@ -6,7 +6,6 @@ - Stimulation | Integer Arithmetic|Computer Organization @@ -24,7 +23,7 @@

Integer Arithmetic

- + @@ -66,7 +65,6 @@

Results

-
diff --git a/experiment/simulation/js/bitwisefbit.js b/experiment/simulation/js/bitwisefbit.js index f924bd6..9b4a305 100644 --- a/experiment/simulation/js/bitwisefbit.js +++ b/experiment/simulation/js/bitwisefbit.js @@ -6,18 +6,18 @@ const messages = [ ] let mat = []; let temp = []; -let ToBeAdded = []; -let SelectedRow = []; -let ColoredIdx = []; -let ResultArray = [0, 0, 0, 0, 0]; +let toBeAdded = []; +let selectedRow = []; +let coloredIdx = []; +let resultArray = [0, 0, 0, 0, 0]; let VisitedArray = [0, 0, 0, 0, 0]; -let ResultArrayname = ['rowbinar', 'row2s', 'row1s', 'rowunsigned', 'rowsigned']; +let resultArrayName = ['rowbinar', 'row2s', 'row1s', 'rowunsigned', 'rowsigned']; let vis = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; -let SameElemFlag = 0; +let sameElemFlag = 0; let glob = 0; let flag = 0; -let valcomplement2 = 0; -let valcomplement1 = 0; +let valComplement2 = 0; +let valComplement1 = 0; let message = messages[0]; document.getElementById("message").innerHTML = message; let width = window.innerWidth || @@ -32,15 +32,15 @@ if (width < 350) { document.getElementById('ef').innerHTML = "Bi na ry"; } -function addoverflow() { +function addOverflow() { for (let i = 0; i < 5; i++) { - console.debug(ResultArray[i]); + console.debug(resultArray[i]); } console.debug("inside addrow id=") for (let i = 0; i < 5; i++) { - let rowlet = document.getElementById(ResultArrayname[i]); + let rowlet = document.getElementById(resultArrayName[i]); let newcell = rowlet.insertCell(-1); - if (ResultArray[i] === 0) { + if (resultArray[i] === 0) { newcell.innerHTML = "overflow"; newcell.style.fontSize = "x-small"; newcell.style.backgroundColor = "rgb(164, 198, 82)"; @@ -51,10 +51,10 @@ function addoverflow() { } -function deleterow() { +function deleteRow() { for (let i = 0; i < 5; i++) { if (VisitedArray[i] === 1) { - document.getElementById(ResultArrayname[i]).deleteCell(-1); + document.getElementById(resultArrayName[i]).deleteCell(-1); VisitedArray[i] = 0; } } @@ -80,54 +80,54 @@ function reset() { vis = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; mat = []; temp = []; - ToBeAdded = []; + toBeAdded = []; document.getElementById('binar').innerHTML = ''; document.getElementById('2s').innerHTML = ''; document.getElementById('1s').innerHTML = ''; document.getElementById('unsigned').innerHTML = ''; document.getElementById('signed').innerHTML = ''; glob = 0; - for (let i = 0; i < SelectedRow.length; i++) { - document.getElementById(SelectedRow[i]).style.backgroundColor = 'transparent'; + for (let i = 0; i < selectedRow.length; i++) { + document.getElementById(selectedRow[i]).style.backgroundColor = 'transparent'; } - for (let i = 0; i < ColoredIdx.length; i++) { - document.getElementsByClassName(ColoredIdx[i])[0].style.backgroundColor = 'transparent'; + for (let i = 0; i < coloredIdx.length; i++) { + document.getElementsByClassName(coloredIdx[i])[0].style.backgroundColor = 'transparent'; } - SelectedRow = []; - ColoredIdx = []; - deleterow(); - ResultArray = [0, 0, 0, 0, 0]; + selectedRow = []; + coloredIdx = []; + deleteRow(); + resultArray = [0, 0, 0, 0, 0]; let message = messages[0]; document.getElementById("message").innerHTML = message; } -function addfunc() { +function addFunction() { if (glob === 2) { let ar1 = []; let ar2 = []; for (let i = 0; i < 2; i++) { - for (let j = 0; j < ToBeAdded[i].length; j++) { + for (let j = 0; j < toBeAdded[i].length; j++) { if (i === 0) { - ar1.push(ToBeAdded[i][j]); + ar1.push(toBeAdded[i][j]); } else { - ar2.push(ToBeAdded[i][j]); + ar2.push(toBeAdded[i][j]); } } } - bitadd(ar1, ar2); + bitAdd(ar1, ar2); glob = 0; - ToBeAdded = []; - SameElemFlag = 0; + toBeAdded = []; + sameElemFlag = 0; } } function rowSelection(event) { - let RowNum = event.target.id - console.debug(" rowNum ", RowNum) + let rowNum = event.target.id + console.debug(" rowNum ", rowNum) if (glob === 0) { document.getElementById('binar').innerHTML = ''; document.getElementById('2s').innerHTML = ''; @@ -135,24 +135,24 @@ function rowSelection(event) { document.getElementById('unsigned').innerHTML = ''; document.getElementById('signed').innerHTML = ''; vis = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; - for (let i = 0; i < SelectedRow.length; i++) { - document.getElementById(SelectedRow[i]).style.backgroundColor = 'transparent'; - document.getElementById(SelectedRow[i]).style.color = 'black'; + for (let i = 0; i < selectedRow.length; i++) { + document.getElementById(selectedRow[i]).style.backgroundColor = 'transparent'; + document.getElementById(selectedRow[i]).style.color = 'black'; } - for (let i = 0; i < ColoredIdx.length; i++) { - document.getElementsByClassName(ColoredIdx[i])[0].style.backgroundColor = 'transparent'; - document.getElementsByClassName(ColoredIdx[i])[0].style.color = 'black'; + for (let i = 0; i < coloredIdx.length; i++) { + document.getElementsByClassName(coloredIdx[i])[0].style.backgroundColor = 'transparent'; + document.getElementsByClassName(coloredIdx[i])[0].style.color = 'black'; } - SelectedRow = []; - ColoredIdx = []; - deleterow(); - ResultArray = [0, 0, 0, 0, 0]; + selectedRow = []; + coloredIdx = []; + deleteRow(); + resultArray = [0, 0, 0, 0, 0]; } - console.debug(RowNum); + console.debug(rowNum); let table = document.getElementById("five-bit-table"); for (let r = 1, n = table.rows.length; r < n; r++) { @@ -164,37 +164,37 @@ function rowSelection(event) { } for (let r = 0; r < table.rows.length - 1; r++) { - if (mat[r][0] === RowNum) { + if (mat[r][0] === rowNum) { glob++; if (glob <= 2) { - ToBeAdded.push(mat[r][1]); - vis[RowNum] = 1; - SelectedRow.push(RowNum); - if (ToBeAdded.length === 2) { - if (ToBeAdded[0] === ToBeAdded[1]) { - SameElemFlag = 1; + toBeAdded.push(mat[r][1]); + vis[rowNum] = 1; + selectedRow.push(rowNum); + if (toBeAdded.length === 2) { + if (toBeAdded[0] === toBeAdded[1]) { + sameElemFlag = 1; } } - document.getElementById(RowNum).style.backgroundColor = '#5da0d1'; + document.getElementById(rowNum).style.backgroundColor = '#5da0d1'; let message = messages[0]; document.getElementById("message").innerHTML = message; } else { - ToBeAdded.splice(1); + toBeAdded.splice(1); glob = 2; - if (SameElemFlag === 0) { - document.getElementById(SelectedRow[1]).style.backgroundColor = 'transparent'; - vis[SelectedRow[1]] = 0; + if (sameElemFlag === 0) { + document.getElementById(selectedRow[1]).style.backgroundColor = 'transparent'; + vis[selectedRow[1]] = 0; } else { - SameElemFlag = 0; + sameElemFlag = 0; } - SelectedRow.splice(1); - SelectedRow.push(RowNum); - ToBeAdded.push(mat[r][1]) - if (ToBeAdded[0] === ToBeAdded[1]) { - SameElemFlag = 1; + selectedRow.splice(1); + selectedRow.push(rowNum); + toBeAdded.push(mat[r][1]) + if (toBeAdded[0] === toBeAdded[1]) { + sameElemFlag = 1; } - document.getElementById(RowNum).style.backgroundColor = '#5da0d1'; - vis[RowNum] = 1; + document.getElementById(rowNum).style.backgroundColor = '#5da0d1'; + vis[rowNum] = 1; } @@ -204,7 +204,7 @@ function rowSelection(event) { } let carry = 0; -function bitadd(a, b) { +function bitAdd(a, b) { let c = []; for (let i = a.length - 1; i >= 0; i--) { if (a[i] === '1' && b[i] === '1') { @@ -241,31 +241,31 @@ function bitadd(a, b) { document.getElementById('unsigned').innerHTML = unsigned(str1); function unsigned(result) { - let unsignval = 0; + let unsignValue = 0; if (result[result.length - 1] === '1') { - unsignval = 1; + unsignValue = 1; } for (let i = result.length - 2; i >= 0; i--) { if (result[i] === '1') { - unsignval += Math.pow(2, result.length - 1 - i); + unsignValue += Math.pow(2, result.length - 1 - i); } } - return unsignval; + return unsignValue; } document.getElementById('signed').innerHTML = signed(str1); function signed(result) { - let signval = 0; + let signValue = 0; let sign = ""; if (a[0] === b[0] && result[0] != a[0]) { - signval = unsigned(str1); + signValue = unsigned(str1); } else { if (result[result.length - 1] === '1') { - signval = 1; + signValue = 1; } for (let i = result.length - 2; i >= 0; i--) { if (result[i] === '1' && i != 0) { - signval += Math.pow(2, result.length - 1 - i); + signValue += Math.pow(2, result.length - 1 - i); } if (i === 0) { if (result[i] === '1') { @@ -273,27 +273,27 @@ function bitadd(a, b) { } } } - if (signval === 0) { + if (signValue === 0) { sign = ""; } } - signval = sign + signval; - return signval; + signValue = sign + signValue; + return signValue; } - onescomplement(str1); + onesComplement(str1); - function onescomplement(result) { + function onesComplement(result) { let complement1 = ""; - valcomplement1 = 0; + valComplement1 = 0; if (a[0] === b[0] && result[0] != a[0]) { console.debug("hi there i am here"); - valcomplement1 = unsigned(str1); - let valcomplement2 = valcomplement1; + valComplement1 = unsigned(str1); + let valComplement2 = valComplement1; } else { if (result[0] === '0') { - valcomplement1 = unsigned(result); - let valcomplement2 = valcomplement1; + valComplement1 = unsigned(result); + let valComplement2 = valComplement1; } else { for (let i = 0; i < result.length; i++) { if (result[i] === '0') { @@ -303,23 +303,23 @@ function bitadd(a, b) { } } - valcomplement1 = "-" + unsigned(complement1); + valComplement1 = "-" + unsigned(complement1); if (unsigned(complement1) === 0) { - valcomplement1 = 0; + valComplement1 = 0; } - twoscomplement(complement1); + twosComplement(complement1); } } } - function setgreencolor(idx, strin) { + function setGreenColor(idx, strin) { let flag = 0; for (let i = 0; i < 32; i++) { if (mat[i][idx] === strin) { let index = (100 * (i + 1) + idx); console.debug("green ", index); - ColoredIdx.push(index); + coloredIdx.push(index); document.getElementsByClassName(index)[0].style.backgroundColor = 'rgb(164, 198, 82)'; document.getElementsByClassName(index)[0].style.color = 'white'; @@ -330,10 +330,10 @@ function bitadd(a, b) { return flag; } - function twoscomplement(result) { + function twosComplement(result) { let complement = []; let complement2 = ""; - valcomplement2 = 0; + valComplement2 = 0; carry = 1; for (let i = result.length - 1; i >= 0; i--) { if (carry === 0) { @@ -363,18 +363,18 @@ function bitadd(a, b) { } } } - valcomplement2 = "-" + unsigned(complement2); + valComplement2 = "-" + unsigned(complement2); } console.debug("inside add part"); document.getElementById('binar').innerHTML = str1; - document.getElementById('2s').innerHTML = valcomplement2; - document.getElementById('1s').innerHTML = valcomplement1; - ResultArray[0] = setgreencolor(1, document.getElementById('binar').innerHTML); - ResultArray[1] = setgreencolor(2, document.getElementById('2s').innerHTML); - ResultArray[2] = setgreencolor(3, document.getElementById('1s').innerHTML); - ResultArray[3] = setgreencolor(4, document.getElementById('unsigned').innerHTML); - ResultArray[4] = setgreencolor(5, document.getElementById('signed').innerHTML); - addoverflow(); + document.getElementById('2s').innerHTML = valComplement2; + document.getElementById('1s').innerHTML = valComplement1; + resultArray[0] = setGreenColor(1, document.getElementById('binar').innerHTML); + resultArray[1] = setGreenColor(2, document.getElementById('2s').innerHTML); + resultArray[2] = setGreenColor(3, document.getElementById('1s').innerHTML); + resultArray[3] = setGreenColor(4, document.getElementById('unsigned').innerHTML); + resultArray[4] = setGreenColor(5, document.getElementById('signed').innerHTML); + addOverflow(); let message = messages[1]; document.getElementById("message").innerHTML = message; } \ No newline at end of file diff --git a/experiment/simulation/js/main.js b/experiment/simulation/js/main.js index 0671f1f..76244cf 100644 --- a/experiment/simulation/js/main.js +++ b/experiment/simulation/js/main.js @@ -6,46 +6,46 @@ const messages = [ ]; let mat = []; let temp = []; -let ToBeAdded = []; -let SelectedRow = []; -let ColoredIdx = []; -let ResultArray = [0, 0, 0, 0, 0]; -let VisitedArray = [0, 0, 0, 0, 0]; -let ResultArrayname = ['rowbinar', 'row2s', 'row1s', 'rowunsigned', 'rowsigned']; +let toBeAdded = []; +let selectedRow = []; +let coloredIdx = []; +let resultArray = [0, 0, 0, 0, 0]; +let visitedArray = [0, 0, 0, 0, 0]; +let resultArrayName = ['rowbinar', 'row2s', 'row1s', 'rowunsigned', 'rowsigned']; let vis = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; -let SameElemFlag = 0; +let sameElemFlag = 0; let glob = 0; let flag = 0; -let afteradd = 0; -let valcomplement2 = 0; -let valcomplement1 = 0; +let afterAdd = 0; +let valComplement2 = 0; +let valComplement1 = 0; let message = messages[0]; document.getElementById("message").innerHTML = message; -function addoverflow() { +function addOverflow() { for (let i = 0; i < 5; i++) { - console.debug(ResultArray[i]); + console.debug(resultArray[i]); } console.debug("inside addrow id=") for (let i = 0; i < 5; i++) { - let rowlet = document.getElementById(ResultArrayname[i]); + let rowlet = document.getElementById(resultArrayName[i]); let newcell = rowlet.insertCell(-1); - if (ResultArray[i] === 0) { + if (resultArray[i] === 0) { newcell.innerHTML = "overflow"; newcell.style.fontSize = "x-small"; newcell.style.backgroundColor = "rgb(164, 198, 82)"; newcell.style.fontWeight = 'bolder'; } - VisitedArray[i] = 1; + visitedArray[i] = 1; } } -function deleterow() { +function deleteRow() { for (let i = 0; i < 5; i++) { - if (VisitedArray[i] === 1) { - document.getElementById(ResultArrayname[i]).deleteCell(-1); - VisitedArray[i] = 0; + if (visitedArray[i] === 1) { + document.getElementById(resultArrayName[i]).deleteCell(-1); + visitedArray[i] = 0; } } @@ -69,56 +69,56 @@ function reset() { vis = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; mat = []; temp = []; - ToBeAdded = []; + toBeAdded = []; document.getElementById('binar').innerHTML = ''; document.getElementById('2s').innerHTML = ''; document.getElementById('1s').innerHTML = ''; document.getElementById('unsigned').innerHTML = ''; document.getElementById('signed').innerHTML = ''; - if (glob != 0 || afteradd === 1) { - afteradd = 0; + if (glob != 0 || afterAdd === 1) { + afterAdd = 0; } glob = 0; - for (let i = 0; i < SelectedRow.length; i++) { - document.getElementById(SelectedRow[i]).style.backgroundColor = 'transparent'; + for (let i = 0; i < selectedRow.length; i++) { + document.getElementById(selectedRow[i]).style.backgroundColor = 'transparent'; } - for (let i = 0; i < ColoredIdx.length; i++) { - document.getElementsByClassName(ColoredIdx[i])[0].style.backgroundColor = 'transparent'; + for (let i = 0; i < coloredIdx.length; i++) { + document.getElementsByClassName(coloredIdx[i])[0].style.backgroundColor = 'transparent'; } - SelectedRow = []; - ColoredIdx = []; - deleterow(); - ResultArray = [0, 0, 0, 0, 0]; + selectedRow = []; + coloredIdx = []; + deleteRow(); + resultArray = [0, 0, 0, 0, 0]; let message = messages[0]; document.getElementById("message").innerHTML = message; } -function addfunc() { +function addFunction() { if (glob === 2) { let ar1 = []; let ar2 = []; for (let i = 0; i < 2; i++) { - for (let j = 0; j < ToBeAdded[i].length; j++) { + for (let j = 0; j < toBeAdded[i].length; j++) { if (i === 0) { - ar1.push(ToBeAdded[i][j]); + ar1.push(toBeAdded[i][j]); } else { - ar2.push(ToBeAdded[i][j]); + ar2.push(toBeAdded[i][j]); } } } - bitadd(ar1, ar2); + bitAdd(ar1, ar2); glob = 0; - ToBeAdded = []; - SameElemFlag = 0; - afteradd = 1; + toBeAdded = []; + sameElemFlag = 0; + afterAdd = 1; } } function rowSelection(event) { - let RowNum = event.target.id - console.debug(" rowNum ", RowNum) + let rowNum = event.target.id + console.debug(" rowNum ", rowNum) if (glob === 0) { document.getElementById('binar').innerHTML = ''; document.getElementById('2s').innerHTML = ''; @@ -126,21 +126,21 @@ function rowSelection(event) { document.getElementById('unsigned').innerHTML = ''; document.getElementById('signed').innerHTML = ''; vis = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; - for (let i = 0; i < SelectedRow.length; i++) { - document.getElementById(SelectedRow[i]).style.backgroundColor = 'transparent'; - document.getElementById(SelectedRow[i]).style.color = 'black'; + for (let i = 0; i < selectedRow.length; i++) { + document.getElementById(selectedRow[i]).style.backgroundColor = 'transparent'; + document.getElementById(selectedRow[i]).style.color = 'black'; } - for (let i = 0; i < ColoredIdx.length; i++) { - document.getElementsByClassName(ColoredIdx[i])[0].style.backgroundColor = 'transparent'; - document.getElementsByClassName(ColoredIdx[i])[0].style.color = 'black'; + for (let i = 0; i < coloredIdx.length; i++) { + document.getElementsByClassName(coloredIdx[i])[0].style.backgroundColor = 'transparent'; + document.getElementsByClassName(coloredIdx[i])[0].style.color = 'black'; } - SelectedRow = []; - ColoredIdx = []; - afteradd = 0; - deleterow(); - ResultArray = [0, 0, 0, 0, 0]; + selectedRow = []; + coloredIdx = []; + afterAdd = 0; + deleteRow(); + resultArray = [0, 0, 0, 0, 0]; } let table = document.getElementById("four-bit-table"); @@ -153,38 +153,38 @@ function rowSelection(event) { } for (let r = 0; r < table.rows.length - 1; r++) { - if (mat[r][0] === RowNum) { + if (mat[r][0] === rowNum) { glob++; if (glob <= 2) { - ToBeAdded.push(mat[r][1]); - vis[RowNum] = 1; - SelectedRow.push(RowNum); - if (ToBeAdded.length === 2) { - if (ToBeAdded[0] === ToBeAdded[1]) { - SameElemFlag = 1; + toBeAdded.push(mat[r][1]); + vis[rowNum] = 1; + selectedRow.push(rowNum); + if (toBeAdded.length === 2) { + if (toBeAdded[0] === toBeAdded[1]) { + sameElemFlag = 1; } } - document.getElementById(RowNum).style.backgroundColor = '#5da0d1'; + document.getElementById(rowNum).style.backgroundColor = '#5da0d1'; let message = messages[0]; document.getElementById("message").innerHTML = message; } else { - ToBeAdded.splice(1); + toBeAdded.splice(1); glob = 2; - if (SameElemFlag === 0) { - document.getElementById(SelectedRow[1]).style.backgroundColor = 'transparent'; - vis[SelectedRow[1]] = 0; + if (sameElemFlag === 0) { + document.getElementById(selectedRow[1]).style.backgroundColor = 'transparent'; + vis[selectedRow[1]] = 0; } else { - SameElemFlag = 0; + sameElemFlag = 0; } - SelectedRow.splice(1); - SelectedRow.push(RowNum); - ToBeAdded.push(mat[r][1]); - if (ToBeAdded[0] === ToBeAdded[1]) { - SameElemFlag = 1; + selectedRow.splice(1); + selectedRow.push(rowNum); + toBeAdded.push(mat[r][1]); + if (toBeAdded[0] === toBeAdded[1]) { + sameElemFlag = 1; } - document.getElementById(RowNum).style.backgroundColor = '#5da0d1'; - vis[RowNum] = 1; + document.getElementById(rowNum).style.backgroundColor = '#5da0d1'; + vis[rowNum] = 1; } @@ -194,7 +194,7 @@ function rowSelection(event) { } let carry = 0; -function bitadd(a, b) { +function bitAdd(a, b) { let c = []; for (let i = a.length - 1; i >= 0; i--) { if (a[i] === '1' && b[i] === '1') { @@ -231,31 +231,31 @@ function bitadd(a, b) { document.getElementById('unsigned').innerHTML = unsigned(str1); function unsigned(result) { - let unsignval = 0; + let unsignValueue = 0; if (result[result.length - 1] === '1') { - unsignval = 1; + unsignValueue = 1; } for (let i = result.length - 2; i >= 0; i--) { if (result[i] === '1') { - unsignval += Math.pow(2, result.length - 1 - i); + unsignValueue += Math.pow(2, result.length - 1 - i); } } - return unsignval; + return unsignValueue; } document.getElementById('signed').innerHTML = signed(str1); function signed(result) { - let signval = 0; + let signValueue = 0; let sign = ""; if (a[0] === b[0] && result[0] != a[0]) { - signval = unsigned(str1); + signValueue = unsigned(str1); } else { if (result[result.length - 1] === '1') { - signval = 1; + signValueue = 1; } for (let i = result.length - 2; i >= 0; i--) { if (result[i] === '1' && i != 0) { - signval += Math.pow(2, result.length - 1 - i); + signValueue += Math.pow(2, result.length - 1 - i); } if (i === 0) { if (result[i] === '1') { @@ -263,27 +263,27 @@ function bitadd(a, b) { } } } - if (signval === 0) { + if (signValueue === 0) { sign = ""; } } - signval = sign + signval; + signValueue = sign + signValueue; - return signval; + return signValueue; } - onescomplement(str1); + onesComplement(str1); - function onescomplement(result) { + function onesComplement(result) { let complement1 = ""; - valcomplement1 = 0; + valComplement1 = 0; if (a[0] === b[0] && result[0] != a[0]) { console.debug("hi there i am here"); - valcomplement1 = unsigned(str1); - valcomplement2 = valcomplement1; + valComplement1 = unsigned(str1); + valComplement2 = valComplement1; } else { if (result[0] === '0') { - valcomplement1 = unsigned(result); - valcomplement2 = valcomplement1; + valComplement1 = unsigned(result); + valComplement2 = valComplement1; } else { for (let i = 0; i < result.length; i++) { if (result[i] === '0') { @@ -293,23 +293,23 @@ function bitadd(a, b) { } } - valcomplement1 = "-" + unsigned(complement1); + valComplement1 = "-" + unsigned(complement1); if (unsigned(complement1) === 0) { - valcomplement1 = 0; + valComplement1 = 0; } - twoscomplement(complement1); + twosComplement(complement1); } } } - function setgreencolor(idx, strin) { + function setGreenColor(idx, strin) { let flag = 0; for (let i = 0; i < 16; i++) { if (mat[i][idx] === strin) { let index = (100 * (i + 1) + idx); console.debug("green ", index) - ColoredIdx.push(index); + coloredIdx.push(index); document.getElementsByClassName(index)[0].style.backgroundColor = 'rgb(164, 198, 82)'; document.getElementsByClassName(index)[0].style.color = 'white'; flag = 1; @@ -320,10 +320,10 @@ function bitadd(a, b) { } - function twoscomplement(result) { + function twosComplement(result) { let complement = []; let complement2 = ""; - valcomplement2 = 0; + valComplement2 = 0; carry = 1; for (let i = result.length - 1; i >= 0; i--) { if (carry === 0) { @@ -353,17 +353,17 @@ function bitadd(a, b) { } } } - valcomplement2 = "-" + unsigned(complement2); + valComplement2 = "-" + unsigned(complement2); } document.getElementById('binar').innerHTML = str1; - document.getElementById('2s').innerHTML = valcomplement2; - document.getElementById('1s').innerHTML = valcomplement1; - ResultArray[0] = setgreencolor(1, document.getElementById('binar').innerHTML); - ResultArray[1] = setgreencolor(2, document.getElementById('2s').innerHTML); - ResultArray[2] = setgreencolor(3, document.getElementById('1s').innerHTML); - ResultArray[3] = setgreencolor(4, document.getElementById('unsigned').innerHTML); - ResultArray[4] = setgreencolor(5, document.getElementById('signed').innerHTML); - addoverflow(); + document.getElementById('2s').innerHTML = valComplement2; + document.getElementById('1s').innerHTML = valComplement1; + resultArray[0] = setGreenColor(1, document.getElementById('binar').innerHTML); + resultArray[1] = setGreenColor(2, document.getElementById('2s').innerHTML); + resultArray[2] = setGreenColor(3, document.getElementById('1s').innerHTML); + resultArray[3] = setGreenColor(4, document.getElementById('unsigned').innerHTML); + resultArray[4] = setGreenColor(5, document.getElementById('signed').innerHTML); + addOverflow(); let message = messages[1]; document.getElementById("message").innerHTML = message; From 95fa4bb9e06f0047b5dd72f7994c7600a77e2d4a Mon Sep 17 00:00:00 2001 From: sravanthi657 <71112579+sravanthi657@users.noreply.github.com> Date: Tue, 27 Apr 2021 00:43:29 +0530 Subject: [PATCH 09/20] Update bitwisefbit.js --- experiment/simulation/js/bitwisefbit.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/experiment/simulation/js/bitwisefbit.js b/experiment/simulation/js/bitwisefbit.js index 9b4a305..8cf2961 100644 --- a/experiment/simulation/js/bitwisefbit.js +++ b/experiment/simulation/js/bitwisefbit.js @@ -10,7 +10,7 @@ let toBeAdded = []; let selectedRow = []; let coloredIdx = []; let resultArray = [0, 0, 0, 0, 0]; -let VisitedArray = [0, 0, 0, 0, 0]; +let visitedArray = [0, 0, 0, 0, 0]; let resultArrayName = ['rowbinar', 'row2s', 'row1s', 'rowunsigned', 'rowsigned']; let vis = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; let sameElemFlag = 0; @@ -377,4 +377,4 @@ function bitAdd(a, b) { addOverflow(); let message = messages[1]; document.getElementById("message").innerHTML = message; -} \ No newline at end of file +} From ac26930e195de5d04becb72d0ea3b5349353bae6 Mon Sep 17 00:00:00 2001 From: sravanthi657 <71112579+sravanthi657@users.noreply.github.com> Date: Thu, 29 Apr 2021 21:54:51 +0530 Subject: [PATCH 10/20] name change --- experiment/simulation/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/experiment/simulation/index.html b/experiment/simulation/index.html index feaf733..9a68a44 100644 --- a/experiment/simulation/index.html +++ b/experiment/simulation/index.html @@ -25,7 +25,7 @@

Integer Arithmetic

- + @@ -223,4 +223,4 @@

Results

- \ No newline at end of file + From d1bc9769d1cfa06f1f292fd822c02d5af396c178 Mon Sep 17 00:00:00 2001 From: sravanthi657 <71112579+sravanthi657@users.noreply.github.com> Date: Thu, 29 Apr 2021 22:03:37 +0530 Subject: [PATCH 11/20] name change --- experiment/simulation/js/bitwisefbit.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/experiment/simulation/js/bitwisefbit.js b/experiment/simulation/js/bitwisefbit.js index 8cf2961..e76a3b8 100644 --- a/experiment/simulation/js/bitwisefbit.js +++ b/experiment/simulation/js/bitwisefbit.js @@ -46,16 +46,16 @@ function addOverflow() { newcell.style.backgroundColor = "rgb(164, 198, 82)"; newcell.style.fontWeight = 'bold'; } - VisitedArray[i] = 1; + visitedArray[i] = 1; } } function deleteRow() { for (let i = 0; i < 5; i++) { - if (VisitedArray[i] === 1) { + if (visitedArray[i] === 1) { document.getElementById(resultArrayName[i]).deleteCell(-1); - VisitedArray[i] = 0; + visitedArray[i] = 0; } } From c233d2498041565bb6a9751a68a8b30acf8cc17f Mon Sep 17 00:00:00 2001 From: sravanthi657 <71112579+sravanthi657@users.noreply.github.com> Date: Thu, 29 Apr 2021 23:01:41 +0530 Subject: [PATCH 12/20] Update main.js --- experiment/simulation/js/main.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/experiment/simulation/js/main.js b/experiment/simulation/js/main.js index 76244cf..e9d8d22 100644 --- a/experiment/simulation/js/main.js +++ b/experiment/simulation/js/main.js @@ -81,10 +81,12 @@ function reset() { glob = 0; for (let i = 0; i < selectedRow.length; i++) { document.getElementById(selectedRow[i]).style.backgroundColor = 'transparent'; + document.getElementsByClassName(coloredIdx[i])[0].style.color = 'black'; } for (let i = 0; i < coloredIdx.length; i++) { document.getElementsByClassName(coloredIdx[i])[0].style.backgroundColor = 'transparent'; + document.getElementsByClassName(coloredIdx[i])[0].style.color = 'black'; } selectedRow = []; coloredIdx = []; @@ -367,4 +369,4 @@ function bitAdd(a, b) { let message = messages[1]; document.getElementById("message").innerHTML = message; -} \ No newline at end of file +} From d2ffb072ca1f6f94e546300f8b26d679ac469c1c Mon Sep 17 00:00:00 2001 From: sravanthi657 <71112579+sravanthi657@users.noreply.github.com> Date: Thu, 29 Apr 2021 23:02:36 +0530 Subject: [PATCH 13/20] Update bitwisefbit.js --- experiment/simulation/js/bitwisefbit.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/experiment/simulation/js/bitwisefbit.js b/experiment/simulation/js/bitwisefbit.js index e76a3b8..4e6a4b2 100644 --- a/experiment/simulation/js/bitwisefbit.js +++ b/experiment/simulation/js/bitwisefbit.js @@ -89,10 +89,12 @@ function reset() { glob = 0; for (let i = 0; i < selectedRow.length; i++) { document.getElementById(selectedRow[i]).style.backgroundColor = 'transparent'; + document.getElementsByClassName(coloredIdx[i])[0].style.color = 'black'; } for (let i = 0; i < coloredIdx.length; i++) { document.getElementsByClassName(coloredIdx[i])[0].style.backgroundColor = 'transparent'; + document.getElementsByClassName(coloredIdx[i])[0].style.color = 'black'; } selectedRow = []; coloredIdx = []; From be9843364b571a65154b40714abc546a4ccf21dc Mon Sep 17 00:00:00 2001 From: sravanthi657 <71112579+sravanthi657@users.noreply.github.com> Date: Thu, 29 Apr 2021 23:07:24 +0530 Subject: [PATCH 14/20] Update bitwisefbit.js --- experiment/simulation/js/bitwisefbit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/experiment/simulation/js/bitwisefbit.js b/experiment/simulation/js/bitwisefbit.js index 4e6a4b2..2c646ae 100644 --- a/experiment/simulation/js/bitwisefbit.js +++ b/experiment/simulation/js/bitwisefbit.js @@ -89,7 +89,7 @@ function reset() { glob = 0; for (let i = 0; i < selectedRow.length; i++) { document.getElementById(selectedRow[i]).style.backgroundColor = 'transparent'; - document.getElementsByClassName(coloredIdx[i])[0].style.color = 'black'; + document.getElementById(selectedRow[i]).style.color = 'black'; } for (let i = 0; i < coloredIdx.length; i++) { From 7256db60df41813ce40b64843c4c87a0317d1306 Mon Sep 17 00:00:00 2001 From: sravanthi657 <71112579+sravanthi657@users.noreply.github.com> Date: Thu, 29 Apr 2021 23:08:01 +0530 Subject: [PATCH 15/20] Update main.js --- experiment/simulation/js/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/experiment/simulation/js/main.js b/experiment/simulation/js/main.js index e9d8d22..9c9aca3 100644 --- a/experiment/simulation/js/main.js +++ b/experiment/simulation/js/main.js @@ -81,7 +81,7 @@ function reset() { glob = 0; for (let i = 0; i < selectedRow.length; i++) { document.getElementById(selectedRow[i]).style.backgroundColor = 'transparent'; - document.getElementsByClassName(coloredIdx[i])[0].style.color = 'black'; + document.getElementById(selectedRow[i]).style.color = 'black'; } for (let i = 0; i < coloredIdx.length; i++) { From a52e285b0143193a70813989eae5d33a3a2e0fa1 Mon Sep 17 00:00:00 2001 From: sravanthi Reddy Date: Wed, 5 May 2021 16:22:16 +0530 Subject: [PATCH 16/20] js files are refactored --- experiment/simulation/css/main.css | 1 - experiment/simulation/html/CO1_5-bit.html | 79 ++-- experiment/simulation/index.html | 452 +++++++++++----------- experiment/simulation/js/bitwisefbit.js | 382 ------------------ experiment/simulation/js/main.js | 51 ++- 5 files changed, 298 insertions(+), 667 deletions(-) delete mode 100644 experiment/simulation/js/bitwisefbit.js diff --git a/experiment/simulation/css/main.css b/experiment/simulation/css/main.css index a8d57b7..e4ab3d3 100644 --- a/experiment/simulation/css/main.css +++ b/experiment/simulation/css/main.css @@ -82,7 +82,6 @@ div.operations button { font-weight: bold; font-size: 2vw; color: #363636; - /* min-width: 280px; */ } .message { diff --git a/experiment/simulation/html/CO1_5-bit.html b/experiment/simulation/html/CO1_5-bit.html index 528244c..cd42239 100644 --- a/experiment/simulation/html/CO1_5-bit.html +++ b/experiment/simulation/html/CO1_5-bit.html @@ -25,7 +25,7 @@

Integer Arithmetic

- + @@ -81,7 +81,7 @@

Results

- + 1 00000 0 @@ -89,7 +89,7 @@

Results

0 +0 - + 2 00001 1 @@ -97,7 +97,7 @@

Results

1 1 - + 3 00010 2 @@ -105,7 +105,7 @@

Results

2 2 - + 4 00011 3 @@ -113,7 +113,7 @@

Results

3 3 - + 5 00100 4 @@ -121,7 +121,7 @@

Results

4 4 - + 6 00101 5 @@ -129,7 +129,7 @@

Results

5 5 - + 7 00110 6 @@ -137,7 +137,7 @@

Results

6 6 - + 8 00111 7 @@ -145,7 +145,7 @@

Results

7 7 - + 9 01000 8 @@ -153,7 +153,7 @@

Results

8 8 - + 10 01001 9 @@ -161,7 +161,7 @@

Results

9 9 - + 11 01010 10 @@ -169,15 +169,15 @@

Results

10 10 - + 12 - 01011 - 11 - 11 - 11 - 11 + 01011 + 11 + 11 + 11 + 11 - + 13 01100 12 @@ -185,7 +185,7 @@

Results

12 12 - + 14 01101 13 @@ -193,7 +193,7 @@

Results

13 13 - + 15 01110 14 @@ -201,7 +201,7 @@

Results

14 14 - + 16 01111 15 @@ -209,7 +209,7 @@

Results

15 15 - + 17 10000 -16 @@ -217,7 +217,7 @@

Results

16 -0 - + 18 10001 -15 @@ -225,7 +225,7 @@

Results

17 -1 - + 19 10010 -14 @@ -233,7 +233,7 @@

Results

18 -2 - + 20 10011 -13 @@ -241,7 +241,7 @@

Results

19 -3 - + 21 10100 -12 @@ -249,7 +249,7 @@

Results

20 -4 - + 22 10101 -11 @@ -257,7 +257,7 @@

Results

21 -5 - + 23 10110 -10 @@ -265,7 +265,7 @@

Results

22 -6 - + 24 10111 -9 @@ -273,7 +273,7 @@

Results

23 -7 - + 25 11000 -8 @@ -281,7 +281,7 @@

Results

24 -8 - + 26 11001 -7 @@ -289,7 +289,7 @@

Results

25 -9 - + 27 11010 -6 @@ -297,7 +297,7 @@

Results

26 -10 - + 28 11011 -5 @@ -305,7 +305,7 @@

Results

27 -11 - + 29 11100 -4 @@ -313,7 +313,7 @@

Results

28 -12 - + 30 11101 -3 @@ -321,7 +321,7 @@

Results

29 -13 - + 31 11110 -2 @@ -329,7 +329,7 @@

Results

30 -14 - + 32 11111 -16 @@ -345,7 +345,8 @@

Results

- + + \ No newline at end of file diff --git a/experiment/simulation/index.html b/experiment/simulation/index.html index 9a68a44..7ff6540 100644 --- a/experiment/simulation/index.html +++ b/experiment/simulation/index.html @@ -1,226 +1,226 @@ - - - - - - - - Representation of Integers and their Arithmetic - - - - - -
-
-
-

Integer Arithmetic

-
-
-
-
-
- -
-
-
- - - - - - - -
-
-

Results

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1Binary Rep
22's Comp
31's Comp
4Unsigned
5Signed
-
-
-
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#Binary2's Comp1's CompUnsignedSigned
100000000
200011111
300102222
400113333
501004444
601015555
701106666
801117777
91000-8-78-0
101001-7-69-1
111010-6-510-2
121011-5-411-3
131100-5-312-4
141101-6-213-5
151110-7-114-6
161111-8-015-7
-
-
-
-
- - - - - - - + + + + + + + + Representation of Integers and their Arithmetic + + + + + +
+
+
+

Integer Arithmetic

+
+
+
+
+
+ +
+
+
+ + + + + + + +
+
+

Results

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
1Binary Rep
22's Comp
31's Comp
4Unsigned
5Signed
+
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#Binary2's Comp1's CompUnsignedSigned
100000000
200011111
300102222
400113333
501004444
601015555
701106666
801117777
91000-8-78-0
101001-7-69-1
111010-6-510-2
121011-5-411-3
131100-5-312-4
141101-6-213-5
151110-7-114-6
161111-8-015-7
+
+
+
+
+ + + + + + + \ No newline at end of file diff --git a/experiment/simulation/js/bitwisefbit.js b/experiment/simulation/js/bitwisefbit.js deleted file mode 100644 index 2c646ae..0000000 --- a/experiment/simulation/js/bitwisefbit.js +++ /dev/null @@ -1,382 +0,0 @@ -"use strict"; -const messages = [ - "Hover over the 5-bit table and Select any two rows to add", - "Results are highlighted green and overflow is displayed in result table\nClick on 4-bit table to switch", - "Click on reset to clear and restart anytime", -] -let mat = []; -let temp = []; -let toBeAdded = []; -let selectedRow = []; -let coloredIdx = []; -let resultArray = [0, 0, 0, 0, 0]; -let visitedArray = [0, 0, 0, 0, 0]; -let resultArrayName = ['rowbinar', 'row2s', 'row1s', 'rowunsigned', 'rowsigned']; -let vis = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; -let sameElemFlag = 0; -let glob = 0; -let flag = 0; -let valComplement2 = 0; -let valComplement1 = 0; -let message = messages[0]; -document.getElementById("message").innerHTML = message; -let width = window.innerWidth || - document.documentElement.clientWidth || - document.body.clientWidth; -console.debug("screen width is "); -console.debug(width); -if (width < 350) { - console.debug("hi") - document.getElementById('ab').innerHTML = "Un sig ned"; - document.getElementById('cd').innerHTML = "Si gn ed"; - document.getElementById('ef').innerHTML = "Bi na ry"; -} - -function addOverflow() { - for (let i = 0; i < 5; i++) { - console.debug(resultArray[i]); - } - console.debug("inside addrow id=") - for (let i = 0; i < 5; i++) { - let rowlet = document.getElementById(resultArrayName[i]); - let newcell = rowlet.insertCell(-1); - if (resultArray[i] === 0) { - newcell.innerHTML = "overflow"; - newcell.style.fontSize = "x-small"; - newcell.style.backgroundColor = "rgb(164, 198, 82)"; - newcell.style.fontWeight = 'bold'; - } - visitedArray[i] = 1; - } - -} - -function deleteRow() { - for (let i = 0; i < 5; i++) { - if (visitedArray[i] === 1) { - document.getElementById(resultArrayName[i]).deleteCell(-1); - visitedArray[i] = 0; - } - } - -} - -function mouseOver(event) { - let indx = event.target.id - console.debug("idx ", indx) - if (vis[parseInt(indx)] === 0) { - document.getElementById(indx).style.backgroundColor = '#c3d8ed'; - } -} - -function mouseOut(event) { - let indx = event.target.id - if (vis[parseInt(indx)] === 0) { - document.getElementById(indx).style.backgroundColor = 'transparent'; - } -} - -function reset() { - vis = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; - mat = []; - temp = []; - toBeAdded = []; - document.getElementById('binar').innerHTML = ''; - document.getElementById('2s').innerHTML = ''; - document.getElementById('1s').innerHTML = ''; - document.getElementById('unsigned').innerHTML = ''; - document.getElementById('signed').innerHTML = ''; - glob = 0; - for (let i = 0; i < selectedRow.length; i++) { - document.getElementById(selectedRow[i]).style.backgroundColor = 'transparent'; - document.getElementById(selectedRow[i]).style.color = 'black'; - - } - for (let i = 0; i < coloredIdx.length; i++) { - document.getElementsByClassName(coloredIdx[i])[0].style.backgroundColor = 'transparent'; - document.getElementsByClassName(coloredIdx[i])[0].style.color = 'black'; - } - selectedRow = []; - coloredIdx = []; - deleteRow(); - resultArray = [0, 0, 0, 0, 0]; - let message = messages[0]; - document.getElementById("message").innerHTML = message; - - -} - -function addFunction() { - if (glob === 2) { - let ar1 = []; - let ar2 = []; - for (let i = 0; i < 2; i++) { - for (let j = 0; j < toBeAdded[i].length; j++) { - if (i === 0) { - ar1.push(toBeAdded[i][j]); - } else { - ar2.push(toBeAdded[i][j]); - } - } - } - bitAdd(ar1, ar2); - glob = 0; - toBeAdded = []; - sameElemFlag = 0; - - } -} - -function rowSelection(event) { - let rowNum = event.target.id - console.debug(" rowNum ", rowNum) - if (glob === 0) { - document.getElementById('binar').innerHTML = ''; - document.getElementById('2s').innerHTML = ''; - document.getElementById('1s').innerHTML = ''; - document.getElementById('unsigned').innerHTML = ''; - document.getElementById('signed').innerHTML = ''; - vis = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; - for (let i = 0; i < selectedRow.length; i++) { - document.getElementById(selectedRow[i]).style.backgroundColor = 'transparent'; - document.getElementById(selectedRow[i]).style.color = 'black'; - - - } - for (let i = 0; i < coloredIdx.length; i++) { - document.getElementsByClassName(coloredIdx[i])[0].style.backgroundColor = 'transparent'; - document.getElementsByClassName(coloredIdx[i])[0].style.color = 'black'; - - } - selectedRow = []; - coloredIdx = []; - deleteRow(); - resultArray = [0, 0, 0, 0, 0]; - } - - console.debug(rowNum); - let table = document.getElementById("five-bit-table"); - - for (let r = 1, n = table.rows.length; r < n; r++) { - temp = []; - for (let c = 0, m = table.rows[r].cells.length; c < m; c++) { - temp.push(table.rows[r].cells[c].innerHTML); - } - mat.push(temp); - - } - for (let r = 0; r < table.rows.length - 1; r++) { - if (mat[r][0] === rowNum) { - glob++; - if (glob <= 2) { - toBeAdded.push(mat[r][1]); - vis[rowNum] = 1; - selectedRow.push(rowNum); - if (toBeAdded.length === 2) { - if (toBeAdded[0] === toBeAdded[1]) { - sameElemFlag = 1; - } - } - document.getElementById(rowNum).style.backgroundColor = '#5da0d1'; - let message = messages[0]; - document.getElementById("message").innerHTML = message; - } else { - toBeAdded.splice(1); - glob = 2; - if (sameElemFlag === 0) { - document.getElementById(selectedRow[1]).style.backgroundColor = 'transparent'; - vis[selectedRow[1]] = 0; - } else { - sameElemFlag = 0; - } - selectedRow.splice(1); - selectedRow.push(rowNum); - toBeAdded.push(mat[r][1]) - if (toBeAdded[0] === toBeAdded[1]) { - sameElemFlag = 1; - } - document.getElementById(rowNum).style.backgroundColor = '#5da0d1'; - vis[rowNum] = 1; - - } - - } - - } -} -let carry = 0; - -function bitAdd(a, b) { - let c = []; - for (let i = a.length - 1; i >= 0; i--) { - if (a[i] === '1' && b[i] === '1') { - if (carry === '1') { - c.push('1'); - } else { - c.push('0'); - carry = '1'; - } - } else if ((a[i] === '0' && b[i] === '1') || (a[i] === '1' && b[i] === '0')) { - if (carry === '1') { - c.push('0'); - } else { - c.push('1'); - } - } else { - if (carry === '1') { - carry = '0'; - c.push('1'); - } else { - c.push('0'); - } - } - - } - if (carry === '1') { - c.push('1'); - } - c.reverse(); - let str1 = ""; - for (let i = 0; i < c.length; i++) { - str1 += c[i]; - } - document.getElementById('unsigned').innerHTML = unsigned(str1); - - function unsigned(result) { - let unsignValue = 0; - if (result[result.length - 1] === '1') { - unsignValue = 1; - } - for (let i = result.length - 2; i >= 0; i--) { - if (result[i] === '1') { - unsignValue += Math.pow(2, result.length - 1 - i); - } - } - return unsignValue; - } - document.getElementById('signed').innerHTML = signed(str1); - - function signed(result) { - let signValue = 0; - let sign = ""; - if (a[0] === b[0] && result[0] != a[0]) { - signValue = unsigned(str1); - } else { - if (result[result.length - 1] === '1') { - signValue = 1; - } - for (let i = result.length - 2; i >= 0; i--) { - if (result[i] === '1' && i != 0) { - signValue += Math.pow(2, result.length - 1 - i); - } - if (i === 0) { - if (result[i] === '1') { - sign = "-"; - } - } - } - if (signValue === 0) { - sign = ""; - } - } - signValue = sign + signValue; - return signValue; - } - - onesComplement(str1); - - function onesComplement(result) { - let complement1 = ""; - valComplement1 = 0; - if (a[0] === b[0] && result[0] != a[0]) { - console.debug("hi there i am here"); - valComplement1 = unsigned(str1); - let valComplement2 = valComplement1; - } else { - if (result[0] === '0') { - valComplement1 = unsigned(result); - let valComplement2 = valComplement1; - } else { - for (let i = 0; i < result.length; i++) { - if (result[i] === '0') { - complement1 += "1"; - } else { - complement1 += "0"; - } - - } - valComplement1 = "-" + unsigned(complement1); - if (unsigned(complement1) === 0) { - valComplement1 = 0; - } - twosComplement(complement1); - } - } - - } - - function setGreenColor(idx, strin) { - let flag = 0; - for (let i = 0; i < 32; i++) { - if (mat[i][idx] === strin) { - let index = (100 * (i + 1) + idx); - console.debug("green ", index); - coloredIdx.push(index); - document.getElementsByClassName(index)[0].style.backgroundColor = 'rgb(164, 198, 82)'; - document.getElementsByClassName(index)[0].style.color = 'white'; - - flag = 1; - break; - } - } - return flag; - } - - function twosComplement(result) { - let complement = []; - let complement2 = ""; - valComplement2 = 0; - carry = 1; - for (let i = result.length - 1; i >= 0; i--) { - if (carry === 0) { - if (result[i] === "0") { - complement.push("0"); - carry = 0; - } else { - complement.push("1"); - carry = 0; - } - } else if (carry === 1) { - if (result[i] === "0") { - complement.push("1"); - carry = 0; - } else { - complement.push("0"); - carry = 1; - } - } - if (i === 0) { - complement.reverse() - for (let j = 0; j < complement.length; j++) { - complement2 += complement[j]; - } - if (carry === 1) { - complement2 = "1" + complement2; - } - } - } - valComplement2 = "-" + unsigned(complement2); - } - console.debug("inside add part"); - document.getElementById('binar').innerHTML = str1; - document.getElementById('2s').innerHTML = valComplement2; - document.getElementById('1s').innerHTML = valComplement1; - resultArray[0] = setGreenColor(1, document.getElementById('binar').innerHTML); - resultArray[1] = setGreenColor(2, document.getElementById('2s').innerHTML); - resultArray[2] = setGreenColor(3, document.getElementById('1s').innerHTML); - resultArray[3] = setGreenColor(4, document.getElementById('unsigned').innerHTML); - resultArray[4] = setGreenColor(5, document.getElementById('signed').innerHTML); - addOverflow(); - let message = messages[1]; - document.getElementById("message").innerHTML = message; -} diff --git a/experiment/simulation/js/main.js b/experiment/simulation/js/main.js index 9c9aca3..6c68d85 100644 --- a/experiment/simulation/js/main.js +++ b/experiment/simulation/js/main.js @@ -9,13 +9,13 @@ let temp = []; let toBeAdded = []; let selectedRow = []; let coloredIdx = []; +let flg2 = 1 let resultArray = [0, 0, 0, 0, 0]; let visitedArray = [0, 0, 0, 0, 0]; let resultArrayName = ['rowbinar', 'row2s', 'row1s', 'rowunsigned', 'rowsigned']; let vis = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; let sameElemFlag = 0; let glob = 0; -let flag = 0; let afterAdd = 0; let valComplement2 = 0; let valComplement1 = 0; @@ -38,7 +38,6 @@ function addOverflow() { } visitedArray[i] = 1; } - } function deleteRow() { @@ -48,7 +47,6 @@ function deleteRow() { visitedArray[i] = 0; } } - } function mouseOver(event) { @@ -65,8 +63,14 @@ function mouseOut(event) { } } -function reset() { - vis = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; +function reset(event) { + let flg = event.target.id; + if (flg == "four-reset") + vis = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + if (flg == "five-reset") { + flg2 = 2 + vis = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + } mat = []; temp = []; toBeAdded = []; @@ -94,7 +98,6 @@ function reset() { resultArray = [0, 0, 0, 0, 0]; let message = messages[0]; document.getElementById("message").innerHTML = message; - } function addFunction() { @@ -118,7 +121,7 @@ function addFunction() { } } -function rowSelection(event) { +function rowSelection(event, flg) { let rowNum = event.target.id console.debug(" rowNum ", rowNum) if (glob === 0) { @@ -127,7 +130,12 @@ function rowSelection(event) { document.getElementById('1s').innerHTML = ''; document.getElementById('unsigned').innerHTML = ''; document.getElementById('signed').innerHTML = ''; - vis = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + if (flg == '1') + vis = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + if (flg == '2') { + flg2 = flg + vis = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + } for (let i = 0; i < selectedRow.length; i++) { document.getElementById(selectedRow[i]).style.backgroundColor = 'transparent'; document.getElementById(selectedRow[i]).style.color = 'black'; @@ -144,8 +152,11 @@ function rowSelection(event) { deleteRow(); resultArray = [0, 0, 0, 0, 0]; } - - let table = document.getElementById("four-bit-table"); + let table = "" + if (flg == '1') + table = document.getElementById("four-bit-table"); + if (flg == '2') + table = document.getElementById("five-bit-table"); for (let r = 1, n = table.rows.length; r < n; r++) { temp = []; for (let c = 0, m = table.rows[r].cells.length; c < m; c++) { @@ -302,12 +313,14 @@ function bitAdd(a, b) { twosComplement(complement1); } } - } - function setGreenColor(idx, strin) { + function setGreenColor(a, idx, strin) { let flag = 0; - for (let i = 0; i < 16; i++) { + let length = 16 + if (a == 2) + length = 32 + for (let i = 0; i < length; i++) { if (mat[i][idx] === strin) { let index = (100 * (i + 1) + idx); console.debug("green ", index) @@ -360,13 +373,13 @@ function bitAdd(a, b) { document.getElementById('binar').innerHTML = str1; document.getElementById('2s').innerHTML = valComplement2; document.getElementById('1s').innerHTML = valComplement1; - resultArray[0] = setGreenColor(1, document.getElementById('binar').innerHTML); - resultArray[1] = setGreenColor(2, document.getElementById('2s').innerHTML); - resultArray[2] = setGreenColor(3, document.getElementById('1s').innerHTML); - resultArray[3] = setGreenColor(4, document.getElementById('unsigned').innerHTML); - resultArray[4] = setGreenColor(5, document.getElementById('signed').innerHTML); + resultArray[0] = setGreenColor(flg2, 1, document.getElementById('binar').innerHTML); + resultArray[1] = setGreenColor(flg2, 2, document.getElementById('2s').innerHTML); + resultArray[2] = setGreenColor(flg2, 3, document.getElementById('1s').innerHTML); + resultArray[3] = setGreenColor(flg2, 4, document.getElementById('unsigned').innerHTML); + resultArray[4] = setGreenColor(flg2, 5, document.getElementById('signed').innerHTML); addOverflow(); let message = messages[1]; document.getElementById("message").innerHTML = message; -} +} \ No newline at end of file From 791a6c37535343f88ccd98d52a902570f9392c37 Mon Sep 17 00:00:00 2001 From: sravanthi Reddy Date: Wed, 5 May 2021 16:39:10 +0530 Subject: [PATCH 17/20] instruction box --- experiment/simulation/css/main.css | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/experiment/simulation/css/main.css b/experiment/simulation/css/main.css index e4ab3d3..4617286 100644 --- a/experiment/simulation/css/main.css +++ b/experiment/simulation/css/main.css @@ -86,10 +86,11 @@ div.operations button { .message { text-align: center; - background-color: rgb(164, 198, 82); + border: solid rgb(164, 198, 82) 0.3rem; font-family: Arial, Helvetica, sans-serif; font-size: 1.5vw; - color: white; + color: #288EC8; + border-radius: 0.5rem; } .br { @@ -155,7 +156,7 @@ div.operations button { @media screen and (max-width: 1570px) { .message { - font-size: 2vh; + font-size: 2.8vh; margin-left: 10px; margin-right: 10px; } @@ -199,7 +200,7 @@ div.operations button { font-size: 70%; } .btn { - font-size: 3vw; + font-size: 3.5vw; width: 30%; } .br { @@ -224,8 +225,11 @@ div.operations button { text-align: center; font-weight: 600; } + .rtable th { + font-size: 4vw; + } .btn { - width: 100%; + width: 60%; font-size: 1vh; } } \ No newline at end of file From e6b7c3030d01b3bb13d8e239dcf6122e4648a6ca Mon Sep 17 00:00:00 2001 From: sravanthi Reddy Date: Wed, 5 May 2021 23:54:59 +0530 Subject: [PATCH 18/20] aligned --- experiment/simulation/css/main.css | 58 +++++++------- .../{CO1_5-bit.html => five-bit_table.html} | 78 +++++++++---------- experiment/simulation/index.html | 48 ++++++------ experiment/simulation/js/main.js | 52 ++++++------- 4 files changed, 112 insertions(+), 124 deletions(-) rename experiment/simulation/html/{CO1_5-bit.html => five-bit_table.html} (86%) diff --git a/experiment/simulation/css/main.css b/experiment/simulation/css/main.css index 4617286..4d7955f 100644 --- a/experiment/simulation/css/main.css +++ b/experiment/simulation/css/main.css @@ -72,6 +72,7 @@ div.operations button { #main-heading { align-content: center; + margin-left: 35%; text-align: center; font-weight: 600; font-size: 2.3vw; @@ -102,7 +103,7 @@ div.operations button { border-radius: 16px; border: none; font-family: sans-serif; - text-align: left; + text-align: center; font-size: 0.7vw; background-color: #288EC8; width: 100px; @@ -117,6 +118,24 @@ div.operations button { font-size: 90%; } +@media screen and (max-width: 1570px) { + .message { + font-size: 2vh; + margin-left: 10px; + margin-right: 10px; + } + #main-heading { + padding-top: 10px; + font-size: 3vh; + } + #result-heading { + font-size: 3vh; + } + .btn { + font-size: 70%; + } +} + @media screen and(max-width: 769px) { #main-heading { padding-top: 10px; @@ -145,8 +164,13 @@ div.operations button { font-weight: bold; } .btn { - font-size: 60%; - width: 44%; + font-size: 65%; + width: 34%; + margin-left: 50%; + } + .br { + display: block; + margin-bottom: 1em; } } @@ -154,24 +178,6 @@ div.operations button { min-width: 100px; } -@media screen and (max-width: 1570px) { - .message { - font-size: 2.8vh; - margin-left: 10px; - margin-right: 10px; - } - #main-heading { - padding-top: 10px; - font-size: 3vh; - } - #result-heading { - font-size: 3vh; - } - .btn { - font-size: 70%; - } -} - @media screen and (max-width: 380px) { .message { font-size: 5vw; @@ -200,8 +206,9 @@ div.operations button { font-size: 70%; } .btn { - font-size: 3.5vw; + font-size: 3.2vw; width: 30%; + margin-left: 40%; } .br { display: block; @@ -225,11 +232,8 @@ div.operations button { text-align: center; font-weight: 600; } - .rtable th { - font-size: 4vw; - } .btn { - width: 60%; - font-size: 1vh; + width: 100%; + font-size: 1.3vh; } } \ No newline at end of file diff --git a/experiment/simulation/html/CO1_5-bit.html b/experiment/simulation/html/five-bit_table.html similarity index 86% rename from experiment/simulation/html/CO1_5-bit.html rename to experiment/simulation/html/five-bit_table.html index cd42239..375cddd 100644 --- a/experiment/simulation/html/CO1_5-bit.html +++ b/experiment/simulation/html/five-bit_table.html @@ -13,7 +13,6 @@
-

Integer Arithmetic

@@ -25,7 +24,7 @@

Integer Arithmetic

- + @@ -73,15 +72,15 @@

Results

# Binary - 2's COMP - 1's COMP - UNSIGNED - SIGNED + 2's Comp + 1's Comp + Unsigned + Signed - + 1 00000 0 @@ -89,7 +88,7 @@

Results

0 +0 - + 2 00001 1 @@ -97,7 +96,7 @@

Results

1 1 - + 3 00010 2 @@ -105,7 +104,7 @@

Results

2 2 - + 4 00011 3 @@ -113,7 +112,7 @@

Results

3 3 - + 5 00100 4 @@ -121,7 +120,7 @@

Results

4 4 - + 6 00101 5 @@ -129,7 +128,7 @@

Results

5 5 - + 7 00110 6 @@ -137,7 +136,7 @@

Results

6 6 - + 8 00111 7 @@ -145,7 +144,7 @@

Results

7 7 - + 9 01000 8 @@ -153,7 +152,7 @@

Results

8 8 - + 10 01001 9 @@ -161,7 +160,7 @@

Results

9 9 - + 11 01010 10 @@ -169,7 +168,7 @@

Results

10 10 - + 12 01011 11 @@ -177,7 +176,7 @@

Results

11 11 - + 13 01100 12 @@ -185,7 +184,7 @@

Results

12 12 - + 14 01101 13 @@ -193,7 +192,7 @@

Results

13 13 - + 15 01110 14 @@ -201,7 +200,7 @@

Results

14 14 - + 16 01111 15 @@ -209,7 +208,7 @@

Results

15 15 - + 17 10000 -16 @@ -217,7 +216,7 @@

Results

16 -0 - + 18 10001 -15 @@ -225,7 +224,7 @@

Results

17 -1 - + 19 10010 -14 @@ -233,7 +232,7 @@

Results

18 -2 - + 20 10011 -13 @@ -241,7 +240,7 @@

Results

19 -3 - + 21 10100 -12 @@ -249,7 +248,7 @@

Results

20 -4 - + 22 10101 -11 @@ -257,7 +256,7 @@

Results

21 -5 - + 23 10110 -10 @@ -265,7 +264,7 @@

Results

22 -6 - + 24 10111 -9 @@ -273,7 +272,7 @@

Results

23 -7 - + 25 11000 -8 @@ -281,7 +280,7 @@

Results

24 -8 - + 26 11001 -7 @@ -289,7 +288,7 @@

Results

25 -9 - + 27 11010 -6 @@ -297,7 +296,7 @@

Results

26 -10 - + 28 11011 -5 @@ -305,7 +304,7 @@

Results

27 -11 - + 29 11100 -4 @@ -313,7 +312,7 @@

Results

28 -12 - + 30 11101 -3 @@ -321,7 +320,7 @@

Results

29 -13 - + 31 11110 -2 @@ -329,7 +328,7 @@

Results

30 -14 - + 32 11111 -16 @@ -343,9 +342,6 @@

Results

- - - diff --git a/experiment/simulation/index.html b/experiment/simulation/index.html index 7ff6540..62717f8 100644 --- a/experiment/simulation/index.html +++ b/experiment/simulation/index.html @@ -14,7 +14,6 @@
-

Integer Arithmetic

@@ -27,9 +26,9 @@

Integer Arithmetic

- + - +
@@ -73,17 +72,17 @@

Results

- - + + - - + + - + @@ -91,7 +90,7 @@

Results

- + @@ -99,7 +98,7 @@

Results

- + @@ -107,7 +106,7 @@

Results

- + @@ -115,7 +114,7 @@

Results

- + @@ -123,7 +122,7 @@

Results

- + @@ -131,7 +130,7 @@

Results

- + @@ -139,7 +138,7 @@

Results

- + @@ -147,7 +146,7 @@

Results

- + @@ -155,7 +154,7 @@

Results

- + @@ -163,7 +162,7 @@

Results

- + @@ -171,7 +170,7 @@

Results

- + @@ -179,7 +178,7 @@

Results

- + @@ -187,7 +186,7 @@

Results

- + @@ -195,7 +194,7 @@

Results

- + @@ -203,7 +202,7 @@

Results

- + @@ -217,9 +216,6 @@

Results

- - - diff --git a/experiment/simulation/js/main.js b/experiment/simulation/js/main.js index 6c68d85..41c053d 100644 --- a/experiment/simulation/js/main.js +++ b/experiment/simulation/js/main.js @@ -65,9 +65,9 @@ function mouseOut(event) { function reset(event) { let flg = event.target.id; - if (flg == "four-reset") + if (flg === "four-reset") vis = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; - if (flg == "five-reset") { + if (flg === "five-reset") { flg2 = 2 vis = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; } @@ -79,7 +79,7 @@ function reset(event) { document.getElementById('1s').innerHTML = ''; document.getElementById('unsigned').innerHTML = ''; document.getElementById('signed').innerHTML = ''; - if (glob != 0 || afterAdd === 1) { + if (glob !== 0 || afterAdd === 1) { afterAdd = 0; } glob = 0; @@ -130,9 +130,9 @@ function rowSelection(event, flg) { document.getElementById('1s').innerHTML = ''; document.getElementById('unsigned').innerHTML = ''; document.getElementById('signed').innerHTML = ''; - if (flg == '1') + if (flg === 1) vis = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; - if (flg == '2') { + if (flg === 2) { flg2 = flg vis = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; } @@ -153,9 +153,9 @@ function rowSelection(event, flg) { resultArray = [0, 0, 0, 0, 0]; } let table = "" - if (flg == '1') + if (flg === 1) table = document.getElementById("four-bit-table"); - if (flg == '2') + if (flg === 2) table = document.getElementById("five-bit-table"); for (let r = 1, n = table.rows.length; r < n; r++) { temp = []; @@ -163,7 +163,6 @@ function rowSelection(event, flg) { temp.push(table.rows[r].cells[c].innerHTML); } mat.push(temp); - } for (let r = 0; r < table.rows.length - 1; r++) { if (mat[r][0] === rowNum) { @@ -198,11 +197,8 @@ function rowSelection(event, flg) { } document.getElementById(rowNum).style.backgroundColor = '#5da0d1'; vis[rowNum] = 1; - } - } - } } let carry = 0; @@ -231,7 +227,6 @@ function bitAdd(a, b) { c.push('0'); } } - } if (carry === '1') { c.push('1'); @@ -244,31 +239,31 @@ function bitAdd(a, b) { document.getElementById('unsigned').innerHTML = unsigned(str1); function unsigned(result) { - let unsignValueue = 0; + let unsignValue = 0; if (result[result.length - 1] === '1') { - unsignValueue = 1; + unsignValue = 1; } for (let i = result.length - 2; i >= 0; i--) { if (result[i] === '1') { - unsignValueue += Math.pow(2, result.length - 1 - i); + unsignValue += Math.pow(2, result.length - 1 - i); } } - return unsignValueue; + return unsignValue; } document.getElementById('signed').innerHTML = signed(str1); function signed(result) { - let signValueue = 0; + let signValue = 0; let sign = ""; - if (a[0] === b[0] && result[0] != a[0]) { - signValueue = unsigned(str1); + if (a[0] === b[0] && result[0] !== a[0]) { + signValue = unsigned(str1); } else { if (result[result.length - 1] === '1') { - signValueue = 1; + signValue = 1; } for (let i = result.length - 2; i >= 0; i--) { - if (result[i] === '1' && i != 0) { - signValueue += Math.pow(2, result.length - 1 - i); + if (result[i] === '1' && i !== 0) { + signValue += Math.pow(2, result.length - 1 - i); } if (i === 0) { if (result[i] === '1') { @@ -276,20 +271,19 @@ function bitAdd(a, b) { } } } - if (signValueue === 0) { + if (signValue === 0) { sign = ""; } } - signValueue = sign + signValueue; - - return signValueue; + signValue = sign + signValue; + return signValue; } onesComplement(str1); function onesComplement(result) { let complement1 = ""; valComplement1 = 0; - if (a[0] === b[0] && result[0] != a[0]) { + if (a[0] === b[0] && result[0] !== a[0]) { console.debug("hi there i am here"); valComplement1 = unsigned(str1); valComplement2 = valComplement1; @@ -318,7 +312,7 @@ function bitAdd(a, b) { function setGreenColor(a, idx, strin) { let flag = 0; let length = 16 - if (a == 2) + if (a === 2) length = 32 for (let i = 0; i < length; i++) { if (mat[i][idx] === strin) { @@ -334,7 +328,6 @@ function bitAdd(a, b) { return flag; } - function twosComplement(result) { let complement = []; let complement2 = ""; @@ -381,5 +374,4 @@ function bitAdd(a, b) { addOverflow(); let message = messages[1]; document.getElementById("message").innerHTML = message; - } \ No newline at end of file From 68ad0d028f0258465920891da877e858f3c25a22 Mon Sep 17 00:00:00 2001 From: sravanthi Reddy Date: Thu, 6 May 2021 00:17:31 +0530 Subject: [PATCH 19/20] minor issues --- experiment/simulation/index.html | 2 +- experiment/simulation/js/main.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/experiment/simulation/index.html b/experiment/simulation/index.html index 62717f8..a700eb0 100644 --- a/experiment/simulation/index.html +++ b/experiment/simulation/index.html @@ -170,7 +170,7 @@

Results

- + diff --git a/experiment/simulation/js/main.js b/experiment/simulation/js/main.js index 41c053d..7916049 100644 --- a/experiment/simulation/js/main.js +++ b/experiment/simulation/js/main.js @@ -13,7 +13,7 @@ let flg2 = 1 let resultArray = [0, 0, 0, 0, 0]; let visitedArray = [0, 0, 0, 0, 0]; let resultArrayName = ['rowbinar', 'row2s', 'row1s', 'rowunsigned', 'rowsigned']; -let vis = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; +let vis = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; let sameElemFlag = 0; let glob = 0; let afterAdd = 0; From 5ab9469a75bad8bcc7398cb08a3a235cd78441eb Mon Sep 17 00:00:00 2001 From: BalammaBoya Date: Wed, 22 Dec 2021 14:15:12 +0530 Subject: [PATCH 20/20] Update procedure.md --- experiment/procedure.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/experiment/procedure.md b/experiment/procedure.md index 6db6e84..fc33eec 100644 --- a/experiment/procedure.md +++ b/experiment/procedure.md @@ -1,6 +1,6 @@ This application is basically designed to make the user understand the difference and similarities between the different arithmetic representations of integers. The key idea is to be able to observe and understand that some of the arithmetic representations behave isomorphically and hence any of them could be interchangeably used at the backend without the knowledge of the user. -## How to use the Application +#### How to use the Application **Step-1:** Select any two rows that you want to add and press the ADD button.
#Binary#Binary 2's Comp 1's CompUnsignedSignedUnsignedSigned
1 0000 0 0 0
2 0001 1 1 1
3 0010 2 2 2
4 0011 3 3 3
5 0100 4 4 4
6 0101 5 5 5
7 0110 6 6 6
8 0111 7 7 7
9 1000 -8 8 -0
10 1001 -7 9 -1
11 1010 -6 10 -2
12 1011 -5 11 -3
13 1100 -5 12 -4
14 1101 -6 13 -5
15 1110 -7 14 -6
16 1111 -8 10 -2
12 1011 -5