Closed Thread Icon

Preserved Topic: Base 16 conversion (JavaScript) (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=18012" title="Pages that link to Preserved Topic: Base 16 conversion (JavaScript) (Page 1 of 1)" rel="nofollow" >Preserved Topic: Base 16 conversion (JavaScript) <span class="small">(Page 1 of 1)</span>\

 
WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 05-28-2001 19:12
code:
while (sum > 0) {
temp = sum % 16;
if (temp == 10)
temp = 'A';
else if (temp == 11)
temp = 'B';
else if (temp == 12)
temp = 'C';
else if (temp == 13)
temp = 'D';
else if (temp == 14)
temp = 'E';
else if (temp == 15)
temp = 'F';

result = "" + temp + "" + result + "";
sum = sum / 16;
}



The result I get is 5e-3248e-3231.285e-3212.0553e-3203.2885e-3195.2616e-3188.4185624e-3171.346969984e-3152.155151975e-3143.4482431603e-3135.51718905651e-3128.8275024904155e-3111.412400398466485e-3092. 2598406375463764e-3083.615745020074202e-3075.785192032118723e-3069.256307251389957e-3051.4810091602223932e-3032.369614656355829e-3023.791383450169327e-3016.066213520270923e-3009.70 5941632433476e-2991.5529506611893562e-2972.48472105790297e-2963.975553692644752e-2956.360885908231603e-2941.0177417453170565e-2921.6283867925072904e-2912.6054188680116646e-2904.168 670188818663e-2896.669872302109861e-2881.0671795683375778e-2861.7074873093401245e-2852.731979694944199e-2844.371167511910719e-2836.99386801905715e-2821.119018883049144e-2801.790430 2128786304e-2792.8646883406058086e-2784.583501344969294e-2777.33360215195087e-2761.1733763443121392e-2741.8774021508994227e-2733.0038434414390764e-2724.806149506302522e-2717.689839 210084035e-2701.2303742736134457e-2681.968598837781513e-2673.149758140450421e-2665.039613024720674e-2658.063380839553077e-2641.2901409343284924e-2622.064225494925588e-2613.30276079 1880941e-2605.284417267009505e-2598.455067627215208e-2581.3528108203544333e-2562.1644973125670932e-2553.463195700107349e-2545.541113120171759e-2538.865780992274814e-2521.4185249587 639702e-2502.2696399340223524e-2493.631423894435764e-2485.810278231097222e-2479.296445169755555e-2461.487431227160889e-2442.379889963457422e-2433.8078239415318754e-2426.09251830645 1001e-2419.748029290321601e-2401.5596846864514562e-2382.49549549832233e-2373.992792797315728e-2366.388468475705164e-2351.0221549561128263e-2331.635447929780522e-2322.61671668764883 54e-2314.186746700238137e-2306.698794720381018e-2291.071807155260963e-2271.7148914484175407e-2262.743826317468065e-2254.390122107948904e-2247.024195372718247e-2231.1238712596349195 e-2211.7981940154158712e-2202.877110424665394e-2194.60337667946463e-2187.365402687143408e-2171.1784644299429453e-2151.8855430879087125e-2143.01686894065394e-2134.826990305046304e-2 127.723184488074086e-2111.235709518091854e-2091.9771352289469662e-2083.163416366315146e-2075.061466186104233e-2068.098345897766773e-2051.2957353436426838e-2032.073176549828294e-202 3.3170824797252705e-2015.307331967560433e-2008.491731148096692e-1991.3586769836954708e-1972.1738831739127532e-1963.478213078260405e-1955.565140925216648e-1948.904225480346637e-1931 .424676076855462e-1912.279481722968739e-1903.647170756749983e-1895.835473210799972e-1889.336757137279955e-1871.493881141964793e-1852.3902098271436686e-1843.82433572342987e-1836.118 937157487792e-1829.790299451980466e-1811.5664479123168747e-1792.5063166597069995e-1784.010106655531199e-1776.416170648849918e-1761.026587303815987e-1741.6425396861055792e-1732.6280 634977689267e-1724.204901596430283e-1716.727842554288452e-1701.0764548086861523e-1681.7223276938978438e-1672.75572431023655e-1664.40915889637848e-1657.054654234205568e-1641.1287446 77472891e-1621.8059914839566254e-1612.889586374330601e-1604.623338198928961e-1597.397341118286338e-1581.183574578925814e-1561.8937193262813025e-1553.029950922050084e-1544.847921475 280134e-1537.756674360448215e-1521.2410678976717144e-1501.985708636274743e-1493.177133818039589e-1485.083414108863342e-1478.133462574181347e-1461.3013540118690156e-1442.08216641899 0425e-1433.33146627038468e-1425.330346032615488e-1418.52855365218478e-1401.364568584349565e-1382.183309734959304e-1373.493295575934886e-1365.589272921495818e-1358.942836674393308e- 1341.4308538679029294e-1322.289366188644687e-1313.662985901831499e-1305.860777442930399e-1299.377243908688637e-1281.500359025390182e-1262.4005744406242913e-1253.840919104998866e-12 46.145470567998186e-1239.832752908797097e-1221.5732404654075355e-1202.517184744652057e-1194.027495591443291e-1186.443992946309265e-1171.0310388714094825e-1151.649662194255172e-1142 .639459510808275e-1134.22313521729324e-1126.757016347669184e-1111.0811226156270695e-1091.7297961850033112e-1082.767673896005298e-1074.428278233608477e-1067.085245173773563e-1051.13 363922780377e-1031.813822764486032e-1022.9021164231776513e-1014.643386277084242e-1007.429418043334787e-991.188706886933566e-971.9019310190937055e-963.043089630549929e-954.868943408 879886e-947.790309454207818e-931.246449512673251e-911.9943192202772014e-903.190910752443522e-895.105457203909636e-888.168731526255417e-871.3069970442008667e-852.0911952707213867e-8 43.345912433154219e-835.35345989304675e-828.5655358288748e-811.370485732619968e-792.192777172191949e-783.508443475507118e-775.613509560811389e-768.981615297298222e-751.437058447567 7156e-732.299293516108345e-723.678869625773352e-715.886191401237363e-709.41790624197978e-691.506864998716765e-672.410983997946824e-663.857574396714918e-656.172119034743869e-649.875 39045559019e-631.5800624728944305e-612.528099956631089e-604.044959930609742e-596.471935888975587e-581.035509742236094e-561.6568155875777503e-552.6509049401244005e-544.2414479041990 41e-536.786316646718465e-521.0858106634749544e-501.737297061559927e-492.7796752984958834e-484.447480477593414e-477.115968764149461e-461.1385550022639138e-441.821688003622262e-432.9 147008057956195e-424.663521289272991e-417.461634062836786e-401.1938614500538857e-381.910178320086217e-373.0562853121379475e-364.890056499420716e-357.824090399073145e-341.2518544638 517033e-322.0029671421627253e-313.2047474274603605e-305.127595883936577e-298.204153414298522e-281.3126645462877636e-262.100263274060422e-253.360421238496675e-245.37667398159468e-23 8.602678370551487e-221.376428539288238e-202.202285662861181e-193.5236570605778894e-185.637851296924623e-179.020562075079396e-161.4432899320127035e-142.3092638912203256e-133.6948222 25952521e-125.911715561524033e-119.458744898438453e-101.5133991837501526e-82.421438694000244e-70.0000038743019104003910.000061988830566406250.00099182128906250.0158691406250.253906 254.06251

for 65... which is no doubt because I don't know how to keep the result an integer.

Could someone help me out with the code. I don't know what to do with it from here.

It is a decimal to base 16 conversion.

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 05-28-2001 19:32

Try this, change

sum = sum / 16;

to

sum = Math.floor(sum/16);

that will truncate any decimal parts of "sum".

[This message has been edited by Slime (edited 05-28-2001).]

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 05-28-2001 19:35

Shit, slime so easy, can't believe I missed it, thanks a lot.

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 05-28-2001 19:39

Why complicate things?

hex = (255).toString(16);
octal = (255).toString(8);
binary = (255).toString(2);

Enjoy!

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 05-28-2001 19:48

You're kidding! I didn't know toString took an argument... wish I had known that before...

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 05-28-2001 19:49

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 05-28-2001 21:48

They have an easy way to go from base 16 back to base 10?

That was a neet little trick there max, saves a ton of time, or would have, had I not already attempted to code it the other way.

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 05-29-2001 04:17

I suppose one could try ("4A3F").toValue(16); a try, but it's really a shot in the dark, and probably won't work...

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 05-29-2001 07:47

People, you're forgetting parseInt()...

parseInt("FF", 16);
parseInt("377", 8);
parseInt("11111111", 2);

Enjoy!

3rdperson
Paranoid (IV) Inmate

From: your subconscious. (scared yet?)
Insane since: May 2001

posted posted 05-29-2001 08:39

threep wishes he was in the forum a little earlier so he could provide at least ONE helpful post before mr 'fount of all coding knowledge' max does....

kars10
Bipolar (III) Inmate

From: Europe
Insane since: Mar 2001

posted posted 05-29-2001 17:08

it's amazig how you gys shortened the code. but wat is it good for?
k10


only change remains

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 05-29-2001 19:16

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

« BackwardsOnwards »

Show Forum Drop Down Menu