Why is this code giving error instead of giving binary number?

what is an overflow error in binary
binary to decimal
binary calculator
rounding error example
how can values greater than 255 be represented in binary
binary overflow
how to do negative numbers in binary
floating point rounding error

Sorry if my question sound silly but I am new to coding and trying to learn javascript. In one of the exercises on edabit, I am supposed to convert a decimal into binary. Here is the code I have written but it's not yielding the desired output. Where am I making a mistake in the code?

```function binary(decimal) {
var arr = [];
var remainderX;
while (decimal > 0) {
remainderX = decimal % 2;
decimal = decimal / 2;
arr.unshift(remainderX);
}
return arr.join('');
}
```

Here is the error I get upon executing the code.

```FAILED: Expected: '1100100', instead got: '5e-3241e-3231.5e-3233e-3236e-3231.24e-3222.47e-3224.94e-3229.9e-3221.976e-3213.953e-3217.905e-3211.581e-3203.162e-3206.324e-3201.2648e-3192.5296e-3195.05923e-3191.011846e-3182.023693e-3184.047386e-3188.09477e-3181.6189543e-3173.2379086e-3176.475817e-3171.29516345e-3162.5903269e-3165.1806538e-3161.036130757e-3152.072261515e-3154.14452303e-3158.28904606e-3151.6578092117e-3143.3156184234e-3146.631236847e-3141.32624736935e-3132.6524947387e-3135.3049894774e-3131.060997895483e-3122.121995790965e-3124.24399158193e-3128.48798316386e-3121.697596632772e-3113.3951932655444e-3116.790386531089e-3111.35807730621777e-3102.71615461243555e-3105.4323092248711e-3101.08646184497422e-3092.17292368994844e-3094.34584737989688e-3098.691694759793755e-3091.738338951958751e-3083.476677903917502e-3086.953355807835004e-3081.3906711615670009e-3072.7813423231340017e-3075.5626846462680035e-3071.1125369292536007e-3062.2250738585072014e-3064.450147717014403e-3068.900295434028806e-3061.780059086805761e-3053.560118173611522e-3057.120236347223044e-3051.4240472694446089e-3042.8480945388892178e-3045.6961890777784355e-3041.1392378155556871e-3032.2784756311113742e-3034.5569512622227484e-3039.113902524445497e-3031.8227805048890994e-3023.645561009778199e-3027.291122019556397e-3021.4582244039112795e-3012.916448807822559e-3015.832897615645118e-3011.1665795231290236e-3002.3331590462580472e-3004.6663180925160944e-3009.332636185032189e-3001.8665272370064378e-2993.7330544740128755e-2997.466108948025751e-2991.4932217896051502e-2982.9864435792103004e-2985.972887158420601e-2981.1945774316841202e-2972.3891548633682403e-2974.7783097267364807e-2979.556619453472961e-2971.9113238906945923e-2963.8226477813891845e-2967.645295562778369e-2961.5290591125556738e-2953.0581182251113476e-2956.116236450222695e-2951.223247290044539e-2942.446494580089078e-2944.892989160178156e-2949.785978320356312e-2941.9571956640712625e-2933.914391328142525e-2937.82878265628505e-2931.56575653125701e-2923.13151306251402e-2926.26302612502804e-2921.252605225005608e-2912.505210450011216e-2915.010420900022432e-2911.0020841800044864e-2902.0041683600089728e-2904.0083367200179456e-2908.016673440035891e-2901.6033346880071782e-2893.2066693760143564e-2896.413338752028713e-2891.2826677504057426e-2882.565335500811485e-2885.13067100162297e-2881.026134200324594e-2872.052268400649188e-2874.104536801298376e-2878.209073602596752e-2871.6418147205193505e-2863.283629441038701e-2866.567258882077402e-2861.3134517764154804e-2852.6269035528309608e-2855.2538071056619216e-2851.0507614211323843e-2842.1015228422647686e-2844.203045684529537e-2848.406091369059075e-2841.681218273811815e-2833.36243654762363e-2836.72487309524726e-2831.344974619049452e-2822.689949238098904e-2825.379898476197808e-2821.0759796952395615e-2812.151959390479123e-2814.303918780958246e-2818.607837561916492e-2811.7215675123832985e-2803.443135024766597e-2806.886270049533194e-2801.3772540099066388e-2792.7545080198132776e-2795.509016039626555e-2791.101803207925311e-2782.203606415850622e-2784.407212831701244e-2788.814425663402488e-2781.7628851326804976e-2773.5257702653609953e-2777.051540530721991e-2771.4103081061443981e-2762.8206162122887962e-2765.6412324245775924e-2761.1282464849155185e-2752.256492969831037e-2754.512985939662074e-2759.025971879324148e-2751.8051943758648296e-2743.610388751729659e-2747.220777503459318e-2741.4441555006918637e-2732.8883110013837273e-2735.776622002767455e-2731.155324400553491e-2722.310648801106982e-2724.621297602213964e-2729.242595204427927e-2721.8485190408855855e-2713.697038081771171e-2717.394076163542342e-2711.4788152327084684e-2702.9576304654169368e-2705.9152609308338736e-2701.1830521861667747e-2692.3661043723335494e-2694.732208744667099e-2699.464417489334198e-2691.8928834978668395e-2683.785766995733679e-2687.571533991467358e-2681.5143067982934716e-2673.0286135965869433e-2676.0572271931738865e-2671.2114454386347773e-2662.4228908772695546e-2664.845781754539109e-2669.691563509078218e-2661.9383127018156437e-2653.8766254036312874e-2657.753250807262575e-2651.550650161452515e-2643.10130032290503e-2646.20260064581006e-2641.240520129162012e-2632.481040258324024e-2634.962080516648048e-2639.924161033296096e-2631.984832206659219e-2623.969664413318438e-2627.939328826636877e-2621.5878657653273753e-2613.1757315306547506e-2616.351463061309501e-2611.2702926122619002e-2602.5405852245238005e-2605.081170449047601e-2601.0162340898095202e-2592.0324681796190404e-2594.064936359238081e-2598.129872718476162e-2591.6259745436952323e-2583.2519490873904646e-2586.503898174780929e-2581.3007796349561859e-2572.6015592699123717e-2575.2031185398247434e-2571.0406237079649487e-2562.0812474159298974e-2564.162494831859795e-2568.32498966371959e-2561.664997932743918e-2553.329995865487836e-2556.659991730975672e-2551.3319983461951343e-2542.6639966923902686e-2545.327993384780537e-2541.0655986769561075e-2532.131197353912215e-2534.26239470782443e-2538.52478941564886e-2531.704957883129772e-2523.409915766259544e-2526.819831532519088e-2521.3639663065038175e-2512.727932613007635e-2515.45586522601527e-2511.091173045203054e-2502.182346090406108e-2504.364692180812216e-2508.729384361624432e-2501.7458768723248864e-2493.491753744649773e-2496.983507489299546e-2491.3967014978599092e-2482.7934029957198183e-2485.586805991439637e-2481.1173611982879273e-2472.2347223965758547e-2474.469444793151709e-2478.938889586303419e-2471.7877779172606837e-2463.5755558345213674e-2467.151111669042735e-2461.430222333808547e-2452.860444667617094e-2455.720889335234188e-2451.1441778670468376e-2442.2883557340936752e-2444.5767114681873503e-2449.153422936374701e-2441.8306845872749401e-2433.6613691745498803e-2437.322738349099761e-2431.4645476698199521e-2422.9290953396399042e-2425.8581906792798084e-2421.1716381358559617e-2412.3432762717119234e-2414.686552543423847e-2419.373105086847693e-2411.8746210173695387e-2403.7492420347390774e-2407.498484069478155e-2401.499696813895631e-2392.999393627791262e-2395.998787255582524e-2391.1997574511165048e-2382.3995149022330095e-2384.799029804466019e-2389.598059608932038e-2381.9196119217864076e-2373.839223843572815e-2377.67844768714563e-2371.535689537429126e-2363.071379074858252e-2366.142758149716504e-2361.2285516299433009e-2352.4571032598866018e-2354.9142065197732035e-2359.828413039546407e-2351.9656826079092814e-2343.931365215818563e-2347.862730431637126e-2341.5725460863274251e-2333.1450921726548502e-2336.2901843453097005e-2331.2580368690619401e-2322.5160737381238802e-2325.0321474762477604e-2321.0064294952495521e-2312.0128589904991042e-2314.0257179809982083e-2318.051435961996417e-2311.6102871923992833e-2303.2205743847985667e-2306.441148769597133e-2301.2882297539194267e-2292.5764595078388533e-2295.152919015677707e-2291.0305838031355413e-2282.0611676062710827e-2284.1223352125421653e-2288.244670425084331e-2281.6489340850168661e-2273.2978681700337323e-2276.5957363400674645e-2271.3191472680134929e-2262.6382945360269858e-2265.2765890720539716e-2261.0553178144107943e-2252.1106356288215886e-2254.221271257643177e-2258.442542515286355e-2251.688508503057271e-2243.377017006114542e-2246.754034012229084e-2241.3508068024458167e-2232.7016136048916335e-2235.403227209783267e-2231.0806454419566534e-2222.1612908839133068e-2224.3225817678266135e-2228.645163535653227e-2221.7290327071306454e-2213.458065414261291e-2216.916130828522582e-2211.3832261657045163e-2202.7664523314090327e-2205.532904662818065e-2201.106580932563613e-2192.213161865127226e-2194.426323730254452e-2198.852647460508905e-2191.770529492101781e-2183.541058984203562e-2187.082117968407124e-2181.4164235936814247e-2172.8328471873628494e-2175.665694374725699e-2171.1331388749451398e-2162.2662777498902796e-2164.532555499780559e-2169.065110999561118e-2161.8130221999122236e-2153.6260443998244473e-2157.252088799648895e-2151.450417759929779e-2142.900835519859558e-2145.801671039719116e-2141.1603342079438231e-2132.3206684158876463e-2134.6413368317752925e-2139.282673663550585e-2131.856534732710117e-2123.713069465420234e-2127.426138930840468e-2121.4852277861680936e-2112.9704555723361872e-2115.9409111446723744e-2111.1881822289344749e-2102.3763644578689498e-2104.7527289157378996e-2109.505457831475799e-2101.9010915662951598e-2093.8021831325903196e-2097.604366265180639e-2091.5208732530361279e-2083.0417465060722557e-2086.0834930121445114e-2081.2166986024289023e-2072.4333972048578046e-2074.866794409715609e-2079.733588819431218e-2071.9467177638862437e-2063.8934355277724873e-2067.786871055544975e-2061.557374211108995e-2053.11474842221799e-2056.22949684443598e-2051.245899368887196e-2042.491798737774392e-2044.983597475548784e-2049.967194951097568e-2041.9934389902195135e-2033.986877980439027e-2037.973755960878054e-2031.5947511921756108e-2023.1895023843512216e-2026.379004768702443e-2021.2758009537404886e-2012.5516019074809773e-2015.1032038149619546e-2011.0206407629923909e-2002.0412815259847818e-2004.0825630519695637e-2008.165126103939127e-2001.6330252207878255e-1993.266050441575651e-1996.532100883151302e-1991.3064201766302604e-1982.6128403532605207e-1985.2256807065210415e-1981.0451361413042083e-1972.0902722826084166e-1974.180544565216833e-1978.361089130433666e-1971.6722178260867333e-1963.3444356521734666e-1966.688871304346933e-1961.3377742608693866e-1952.6755485217387732e-1955.3510970434775465e-1951.0702194086955093e-1942.1404388173910186e-1944.280877634782037e-1948.561755269564074e-1941.7123510539128149e-1933.4247021078256297e-1936.8494042156512595e-1931.3698808431302519e-1922.7397616862605038e-1925.4795233725210076e-1921.0959046745042015e-1912.191809349008403e-1914.383618698016806e-1918.767237396033612e-1911.7534474792067224e-1903.506894958413445e-1907.01378991682689e-1901.402757983365378e-1892.805515966730756e-1895.611031933461512e-1891.1222063866923024e-1882.2444127733846047e-1884.4888255467692094e-1888.977651093538419e-1881.7955302187076838e-1873.5910604374153675e-1877.182120874830735e-1871.436424174966147e-1862.872848349932294e-1865.745696699864588e-1861.1491393399729176e-1852.2982786799458352e-1854.5965573598916705e-1859.193114719783341e-1851.8386229439566682e-1843.6772458879133364e-1847.354491775826673e-1841.4708983551653345e-1832.941796710330669e-1835.883593420661338e-1831.1767186841322676e-1822.3534373682645353e-1824.7068747365290705e-1829.413749473058141e-1821.8827498946116282e-1813.7654997892232564e-1817.530999578446513e-1811.5061999156893026e-1803.012399831378605e-1806.02479966275721e-1801.204959932551442e-1792.409919865102884e-1794.819839730205768e-1799.639679460411536e-1791.9279358920823073e-1783.8558717841646146e-1787.711743568329229e-1781.5423487136658458e-1773.0846974273316917e-1776.169394854663383e-1771.2338789709326767e-1762.4677579418653533e-1764.935515883730707e-1769.871031767461413e-1761.9742063534922827e-1753.9484127069845653e-1757.896825413969131e-1751.5793650827938261e-1743.1587301655876523e-1746.3174603311753045e-1741.2634920662350609e-1732.5269841324701218e-1735.0539682649402436e-1731.0107936529880487e-1722.0215873059760975e-1724.043174611952195e-1728.08634922390439e-1721.617269844780878e-1713.234539689561756e-1716.469079379123512e-1711.2938158758247024e-1702.5876317516494047e-1705.1752635032988095e-1701.0350527006597619e-1692.0701054013195238e-1694.1402108026390476e-1698.280421605278095e-1691.656084321055619e-1683.312168642111238e-1686.624337284222476e-1681.3248674568444952e-1672.6497349136889905e-1675.299469827377981e-1671.0598939654755962e-1662.1197879309511924e-1664.239575861902385e-1668.47915172380477e-1661.695830344760954e-1653.391660689521908e-1656.783321379043816e-1651.3566642758087631e-1642.7133285516175262e-1645.4266571032350524e-1641.0853314206470105e-1632.170662841294021e-1634.341325682588042e-1638.682651365176084e-1631.7365302730352168e-1623.4730605460704336e-1626.946121092140867e-1621.3892242184281734e-1612.778448436856347e-1615.556896873712694e-1611.1113793747425387e-1602.2227587494850775e-1604.445517498970155e-1608.89103499794031e-1601.778206999588062e-1593.556413999176124e-1597.112827998352248e-1591.4225655996704496e-1582.845131199340899e-1585.690262398681798e-1581.1380524797363597e-1572.2761049594727193e-1574.552209918945439e-1579.104419837890877e-1571.8208839675781755e-1563.641767935156351e-1567.283535870312702e-1561.4567071740625404e-1552.9134143481250808e-1555.8268286962501615e-1551.1653657392500323e-1542.3307314785000646e-1544.661462957000129e-1549.322925914000258e-1541.8645851828000517e-1533.7291703656001034e-1537.458340731200207e-1531.4916681462400413e-1522.9833362924800827e-1525.966672584960165e-1521.193334516992033e-1512.386669033984066e-1514.773338067968132e-1519.546676135936265e-1511.909335227187253e-1503.818670454374506e-1507.637340908749012e-1501.5274681817498023e-1493.0549363634996047e-1496.109872726999209e-1491.2219745453998419e-1482.4439490907996837e-1484.8878981815993675e-1489.775796363198735e-1481.955159272639747e-1473.910318545279494e-1477.820637090558988e-1471.5641274181117976e-1463.128254836223595e-1466.25650967244719e-1461.251301934489438e-1452.502603868978876e-1455.005207737957752e-1451.0010415475915505e-1442.002083095183101e-1444.004166190366202e-1448.008332380732404e-1441.6016664761464807e-1433.2033329522929615e-1436.406665904585923e-1431.2813331809171846e-1422.5626663618343692e-1425.1253327236687384e-1421.0250665447337477e-1412.0501330894674953e-1414.1002661789349907e-1418.200532357869981e-1411.6401064715739963e-1403.2802129431479926e-1406.560425886295985e-1401.312085177259197e-1392.624170354518394e-1395.248340709036788e-1391.0496681418073576e-1382.0993362836147152e-1384.1986725672294305e-1388.397345134458861e-1381.6794690268917722e-1373.3589380537835444e-1376.717876107567089e-1371.3435752215134178e-1362.6871504430268355e-1365.374300886053671e-1361.0748601772107342e-1352.1497203544214684e-1354.299440708842937e-1358.598881417685874e-1351.7197762835371747e-1343.4395525670743494e-1346.879105134148699e-1341.3758210268297398e-1332.7516420536594796e-1335.503284107318959e-1331.1006568214637918e-1322.2013136429275836e-1324.402627285855167e-1328.805254571710335e-1321.761050914342067e-1313.522101828684134e-1317.044203657368268e-1311.4088407314736535e-1302.817681462947307e-1305.635362925894614e-1301.1270725851789228e-1292.2541451703578456e-1294.508290340715691e-1299.016580681431383e-1291.8033161362862765e-1283.606632272572553e-1287.213264545145106e-1281.4426529090290212e-1272.8853058180580424e-1275.770611636116085e-1271.154122327223217e-1262.308244654446434e-1264.616489308892868e-1269.232978617785736e-1261.8465957235571472e-1253.6931914471142943e-1257.386382894228589e-1251.4772765788457177e-1242.9545531576914354e-1245.909106315382871e-1241.1818212630765742e-1232.3636425261531484e-1234.727285052306297e-1239.454570104612593e-1231.8909140209225187e-1223.7818280418450374e-1227.563656083690075e-1221.512731216738015e-1213.02546243347603e-1216.05092486695206e-1211.210184973390412e-1202.420369946780824e-1204.840739893561648e-1209.681479787123296e-1201.936295957424659e-1193.872591914849318e-1197.745183829698637e-1191.5490367659397273e-1183.0980735318794546e-1186.196147063758909e-1181.2392294127517818e-1172.4784588255035637e-1174.9569176510071274e-1179.913835302014255e-1171.982767060402851e-1163.965534120805702e-1167.931068241611404e-1161.5862136483222808e-1153.1724272966445615e-1156.344854593289123e-1151.2689709186578246e-1142.5379418373156492e-1145.0758836746312984e-1141.0151767349262597e-1132.0303534698525194e-1134.060706939705039e-1138.121413879410078e-1131.6242827758820155e-1123.248565551764031e-1126.497131103528062e-1121.2994262207056124e-1112.5988524414112248e-1115.1977048828224496e-1111.0395409765644899e-1102.0790819531289798e-1104.1581639062579597e-1108.316327812515919e-1101.6632655625031839e-1093.3265311250063677e-1096.6530622500127355e-1091.3306124500025471e-1082.6612249000050942e-1085.3224498000101884e-1081.0644899600020377e-1072.1289799200040754e-1074.257959840008151e-1078.515919680016301e-1071.7031839360032603e-1063.4063678720065206e-1066.812735744013041e-1061.3625471488026082e-1052.7250942976052165e-1055.450188595210433e-1051.0900377190420866e-1042.1800754380841732e-1044.3601508761683463e-1048.720301752336693e-1041.7440603504673385e-1033.488120700934677e-1036.976241401869354e-1031.3952482803738708e-1022.7904965607477417e-1025.580993121495483e-1021.1161986242990967e-1012.2323972485981933e-1014.4647944971963866e-1018.929588994392773e-1011.7859177988785547e-1003.5718355977571093e-1007.143671195514219e-1001.4287342391028437e-992.8574684782056875e-995.714936956411375e-991.142987391282275e-982.28597478256455e-984.5719495651291e-989.1438991302582e-981.82877982605164e-973.65755965210328e-977.31511930420656e-971.463023860841312e-962.926047721682624e-965.852095443365248e-961.1704190886730496e-952.340838177346099e-954.681676354692198e-959.363352709384397e-951.8726705418768793e-943.7453410837537587e-947.490682167507517e-941.4981364335015035e-932.996272867003007e-935.992545734006014e-931.1985091468012028e-922.3970182936024055e-924.794036587204811e-929.588073174409622e-921.9176146348819244e-913.835229269763849e-917.670458539527698e-911.5340917079055395e-903.068183415811079e-906.136366831622158e-901.2272733663244316e-892.4545467326488633e-894.9090934652977266e-899.818186930595453e-891.9636373861190906e-883.927274772238181e-887.854549544476362e-881.5709099088952725e-873.141819817790545e-876.28363963558109e-871.256727927116218e-862.513455854232436e-865.026911708464872e-861.0053823416929744e-852.0107646833859488e-854.0215293667718976e-858.043058733543795e-851.608611746708759e-843.217223493417518e-846.434446986835036e-841.2868893973670072e-832.5737787947340145e-835.147557589468029e-831.0295115178936058e-822.0590230357872116e-824.118046071574423e-828.236092143148846e-821.6472184286297693e-813.2944368572595385e-816.588873714519077e-811.3177747429038154e-802.6355494858076308e-805.2710989716152616e-801.0542197943230523e-792.1084395886461046e-794.216879177292209e-798.433758354584419e-791.6867516709168837e-783.3735033418337674e-786.747006683667535e-781.349401336733507e-772.698802673467014e-775.397605346934028e-771.0795210693868056e-762.1590421387736112e-764.3180842775472223e-768.636168555094445e-761.727233711018889e-753.454467422037778e-756.908934844075556e-751.3817869688151111e-742.7635739376302223e-745.5271478752604446e-741.1054295750520889e-732.2108591501041778e-734.4217183002083556e-738.843436600416711e-731.7686873200833423e-723.5373746401666845e-727.074749280333369e-721.4149498560666738e-712.8298997121333476e-715.659799424266695e-711.131959884853339e-702.263919769706678e-704.527839539413356e-709.055679078826712e-701.8111358157653425e-693.622271631530685e-697.24454326306137e-691.448908652612274e-682.897817305224548e-685.795634610449096e-681.1591269220898192e-672.3182538441796384e-674.636507688359277e-679.273015376718553e-671.8546030753437107e-663.7092061506874214e-667.418412301374843e-661.4836824602749686e-652.967364920549937e-655.934729841099874e-651.1869459682199748e-642.3738919364399497e-644.7477838728798994e-649.495567745759799e-641.8991135491519597e-633.7982270983039195e-637.596454196607839e-631.5192908393215678e-623.0385816786431356e-626.077163357286271e-621.2154326714572542e-612.4308653429145085e-614.861730685829017e-619.723461371658034e-611.9446922743316068e-603.8893845486632136e-607.778769097326427e-601.5557538194652854e-593.111507638930571e-596.223015277861142e-591.2446030555722283e-582.4892061111444567e-584.9784122222889134e-589.956824444577827e-581.9913648889155653e-573.9827297778311307e-577.965459555662261e-571.5930919111324523e-563.1861838222649046e-566.372367644529809e-561.2744735289059618e-552.5489470578119236e-555.097894115623847e-551.0195788231247695e-542.039157646249539e-544.078315292499078e-548.156630584998156e-541.6313261169996311e-533.2626522339992623e-536.5253044679985245e-531.3050608935997049e-522.6101217871994098e-525.2202435743988196e-521.0440487148797639e-512.0880974297595278e-514.1761948595190557e-518.352389719038111e-511.6704779438076223e-503.3409558876152446e-506.681911775230489e-501.3363823550460978e-492.6727647100921956e-495.345529420184391e-491.0691058840368783e-482.1382117680737565e-484.276423536147513e-488.552847072295026e-481.7105694144590052e-473.4211388289180104e-476.842277657836021e-471.3684555315672042e-462.7369110631344083e-465.473822126268817e-461.0947644252537633e-452.1895288505075267e-454.3790577010150533e-458.758115402030107e-451.7516230804060213e-443.5032461608120427e-447.006492321624085e-441.401298464324817e-432.802596928649634e-435.605193857299268e-431.1210387714598537e-422.2420775429197073e-424.4841550858394146e-428.968310171678829e-421.7936620343357659e-413.5873240686715317e-417.174648137343063e-411.4349296274686127e-402.8698592549372254e-405.739718509874451e-401.1479437019748901e-392.2958874039497803e-394.5917748078995606e-399.183549615799121e-391.8367099231598242e-383.6734198463196485e-387.346839692639297e-381.4693679385278594e-372.9387358770557188e-375.8774717541114375e-371.1754943508222875e-362.350988701644575e-364.70197740328915e-369.4039548065783e-361.88079096131566e-353.76158192263132e-357.52316384526264e-351.504632769052528e-343.009265538105056e-346.018531076210112e-341.2037062152420224e-332.4074124304840448e-334.8148248609680896e-339.629649721936179e-331.9259299443872359e-323.8518598887744717e-327.703719777548943e-321.5407439555097887e-313.0814879110195774e-316.162975822039155e-311.232595164407831e-302.465190328815662e-304.930380657631324e-309.860761315262648e-301.9721522630525295e-293.944304526105059e-297.888609052210118e-291.5777218104420236e-283.155443620884047e-286.310887241768094e-281.2621774483536189e-272.5243548967072378e-275.0487097934144756e-271.0097419586828951e-262.0194839173657902e-264.0389678347315804e-268.077935669463161e-261.6155871338926322e-253.2311742677852644e-256.462348535570529e-251.2924697071141057e-242.5849394142282115e-245.169878828456423e-241.0339757656912846e-232.0679515313825692e-234.1359030627651384e-238.271806125530277e-231.6543612251060553e-223.3087224502121107e-226.617444900424221e-221.3234889800848443e-212.6469779601696886e-215.293955920339377e-211.0587911840678754e-202.1175823681357508e-204.2351647362715017e-208.470329472543003e-201.6940658945086007e-193.3881317890172014e-196.776263578034403e-191.3552527156068805e-182.710505431213761e-185.421010862427522e-181.0842021724855044e-172.168404344971009e-174.336808689942018e-178.673617379884035e-171.734723475976807e-163.469446951953614e-166.938893903907228e-161.3877787807814457e-152.7755575615628914e-155.551115123125783e-151.1102230246251565e-142.220446049250313e-144.440892098500626e-148.881784197001252e-141.7763568394002505e-133.552713678800501e-137.105427357601002e-131.4210854715202004e-122.8421709430404007e-125.6843418860808015e-121.1368683772161603e-112.2737367544323206e-114.547473508864641e-119.094947017729282e-111.8189894035458565e-103.637978807091713e-107.275957614183426e-101.4551915228366852e-92.9103830456733704e-95.820766091346741e-91.1641532182693481e-82.3283064365386963e-84.6566128730773926e-89.313225746154785e-81.862645149230957e-73.725290298461914e-77.450580596923828e-70.00000149011611938476560.00000298023223876953120.00000596046447753906250.0000119209289550781250.000023841857910156250.00004768371582031250.0000953674316406250.000190734863281250.00038146972656250.0007629394531250.001525878906250.00305175781250.0061035156250.012207031250.02441406250.0488281250.097656250.19531250.3906250.781251.56251.1250.250.5100'
FAILED: Expected: '0', instead got: ''
```

Use `Math.floor()`

Divsion returns `float` when you do `decimal/2`

```function binary(decimal) {
var arr = [];
var remainderX;
while (decimal > 0) {
remainderX = decimal % 2;
decimal = Math.floor(decimal / 2);
arr.unshift(remainderX);
}
return arr.join('');
}

console.log(binary(10))```

Overflow - Numbers and binary addition, A CPU. with a capacity of 8 bits. has a capacity of up to 11111111 in binary . If one more bit was added there would be an overflow. error. Thus, we use binary number system in computers. So, every computer program first gets converted to these binary codes (machine code) and then this code makes the computer do our work. A common question that arises here is that can we use three states (low, medium and high) instead of only two and use base 3 number system?

There is a very easy way to do what you want:

```function binary(decimal) {
return Number(decimal).toString(2);
}
```

Gray code, The reflected binary code (RBC), also known just as reflected binary (RB) or Gray code after Frank Gray, is an ordering of the binary numeral system such In modern digital communications, Gray codes play an important role in error correction. Gray code addressing instead of binary addressing can reduce the number of� When numbers are stored, a corresponding binary number can represent every number or fractional number. For example, the fraction 1/10 can be represented in a decimal number system as 0.1. However, the same number in binary format becomes the following repeating binary decimal: 0001100110011100110011 (and so on) This can be infinitely repeated.

The problems in your code is:

while calculating new decimal value using the code `decimal = decimal / 2;`, you are not finding whole number quotient. Instead you are trying to divide the decimal number with fraction quotient, which is incorrect method while converting decimal value to binary value. So you should use `decimal = Math.floor(decimal / 2);` which will return whole number quotient for calculating next decimal value for next iteration.

To test it now, just paste following code in this online java script editor (link : [https://js.do/code/391202][1])

test code :

```<script>

function binary(decimal) {
var arr = [];
var remainderX;
while (decimal > 0) {
remainderX = decimal % 2;
//document.write("fraction quotient = "+decimal / 2+"</br>")
decimal = Math.floor(decimal / 2);
//document.write("Whole Number quotient = "+decimal+"</br>")
arr.unshift(remainderX);
}
return arr.join('');
}

binary_vlue = binary(7)
document.write("binary value is = "+binary_vlue)
</script>
```

Round-off error, This gives an extra bit of precision so that the roundoff error caused by representation error is reduced. Since floating-point number system� 101 is parsed as a decimal (base 10) number, so you get your expected output. 0101 is parsed as an octal (base 8) number due to the leading zero. The leading zero here works just like the leading 0x prefix that denotes a hexadecimal (base 16) number, except that without the x it's base 8 instead of base 16. † 101 8 = 8 2 + 8 0 = 64 + 1 = 65

What Every Computer Scientist Should Know About Floating-Point , It gives an algorithm for addition, subtraction, multiplication, division and square root, The subtraction did not introduce any error, but rather exposed the error introduced When converting a decimal number back to its unique binary representation, If it probed for a value outside the domain of f , the code for f might well� Binary Code takes each of those combinations and assigns a number to it, like this: Both Off = 0 First Off, Second On = 1 First On, Second Off = 2 Both On = 3 Intermediate Explanation Another way of thinking about it is this: let's give each lightbulb a point value. We'll say the first lightbulb is worth two points, and the second one is worth

Binary Arithmetic, Adding unsigned numbers in binary is quite easy. Addition is done exactly like adding decimal numbers, except that you have only two digits (0 and 1). Even the generation of overflows resulting in error conditions remains unchanged� You are absolutely right – you will (most probably) never write a computer programs in binary code. Instead, developers like you and I use other, more user-friendly programming languages to give instructions to computers. Nevertheless, binary code is probably the most fundamental concept underlying programming and Computer Science.

Integers - Manual, \$a = 0b11111111; // binary number (equivalent to 255 decimal) a number beyond the bounds of the integer type, it will be interpreted as a float instead. Also since the float doesn't have enough precision to give an exact integer result. 2. there is no unsighed int in PHP, if you use 32 bit version，the code above will get� 🎓 What do binary numbers represent? In mathematics and digital electronics, a binary number is a number expressed in the base-2 numeral system or binary numeral system, which uses only two symbols: typically “0” (zero) and “1” (one). The base-2 numeral system is a positional notation with a radix of 2. Each digit is referred to as a bit.