Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

1. ## Number Bases

/**I am making a program with different bases to show certain numbers starting with unary and going up to base 60 and seeing how that changes. */

background(0, 0, 0);
//unary
var inputnum = 10;

fill(255, 0, 0);
text(inputnum, 50, 50);

//binary
// number.toString( [ baseTo ] ); returns number in desired base.

(inputnum).toString(2);
fill(0, 0, 255);
text((inputnum).toString(2),50,60);

//ternary

(inputnum).toString(3);
fill(69, 201, 24);
text((inputnum).toString(3),50,70);

//Quarternary

(inputnum).toString(4);
fill(237, 151, 21);
text((inputnum).toString(4),50,80);

//Quinary

(inputnum).toString(5);
fill(122, 176, 51);
text((inputnum).toString(5),50,90);

//Senary

(inputnum).toString(6);
fill(0, 225, 255);
text((inputnum).toString(6),50,100);

//Septanary

(inputnum).toString(7);
fill(255, 0, 255);
text((inputnum).toString(7),50,110);

//Octal

(inputnum).toString(8);
fill(102, 0, 255);
text((inputnum).toString(8),50,120);

//Nonary

(inputnum).toString(9);
fill(242, 5, 159);
text((inputnum).toString(9),50,130);

shows numbers in base 10 as well as binary to nonary or base 2 to base 9.

• I know up top is supposed to be the unary number or in another way a string of the same number of 1s as the number represents but this (number).toString(base) can't accept bases lower than binary or higher than base 36. How can I get both the unary and the bases above base 36 such as base 60?

• This is the wrong section of the forum to post your question
This section is for completed scripts or snippets of working code.
It is not the section to post questions.

If you really want to get a response, you should post to the correct area of the forum.
That area is: JavaScript programming
You can ask the moderators to move it or restate you request in the proper section.

What is it that you are REALLY trying to do? Base 36 is represented by characters 0..9 and a..z
Here is an example of the display of base 2 to base 36 with numbers 2 to (2*base) on each line
Code:
```<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8" />
<title> Untitled </title>
<body>
<div id="debug"></div>
<script type="text/javascript">
var str = '';
for (var j=2; j<=36; j++) {
str += j+': '; for (var i=0; i<=j*2; i++) { str += i.toString(j)+'  '; } str += '<p>';
}
document.getElementById('debug').innerHTML = str;
}
</script>
</body>
</html>```
What characters do you want represent base 37 to 60?
Also, I'm not sure the numbers can be represented in the computer beyond a set limit.

• Originally Posted by jmrker
What characters do you want represent base 37 to 60?
Also, I'm not sure the numbers can be represented in the computer beyond a set limit.
The radix must be an integer between 2 and 36. There is no way to represent radices over 36.

You can generate a unary number as follows:-

Code:
```<script type = "text/javascript">

var a = 4;

var unary = "";
for ( i = 1; i<=a; i++) {
unary += "1";
}

</script>```
I have no idea why anyone would want to do so.

Fewer than one in five female ambassadors are women. - Presenter BBC1

• Originally Posted by Philip M
The radix must be an integer between 2 and 36. There is no way to represent radices over 36.

...

I have no idea why anyone would want to do so.
I would agree with your first statement as it relates to the JS language.

I would disagree with your second statement.
All you need is some character to represent the decimal value of 37 to 60.
You could, for example, use the greek alphabet a additional characters for the new radix.
Or even some of the wing-ding characters to represent the values

Code:
```Dec.   Character
2        0  1
3        0 1 2
4        0 1 2 3
...
10       0 1 2 3 4 5 6 7 8 9
11       0..9 a
12       0..9 a b
...
36       0..9 a..z
...
37       0..9 a..z (alpha character)
38       0..9 a..z (alpha) (beta character)
...
60       0..9 a..z (alpha) (beta) (omega character)```
Code:
```<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8" />

<title> Untitled </title>

<body>
<div id="debug"></div>

<script type="text/javascript">
var str = '';
for (var i=2; i<37; i++) {
str += '36 in BASE '+i + ' = ' + (36).toString(i) + '<br>';
}
str += '...<br>36 in BASE 37 = 0..9 a..z (alpha)<br>'
str += '36 in BASE 38 = 0..9 a..z (alpha) (beta)<br>'
str += '...<br>36 in BASE 60 = 0..9 a..z (alpha) (beta) ... (omega)<br>'
document.getElementById('debug').innerHTML = str;
</script>

</body>
</html>```

And I would agree with your third statement most strongly.

• Originally Posted by jmrker
I would agree with your first statement as it relates to the JS language.

I would disagree with your second statement.
All you need is some character to represent the decimal value of 37 to 60.
You could, for example, use the greek alphabet a additional characters for the new radix.
Or even some of the wing-ding characters to represent the values

And I would agree with your third statement most strongly.
Well, I did have in mind the JS language. I don't see how using Greek etc. characters would create a result which was comprehensible to anyone other than the script author.

Of course, the base 60 is used for time and angles (trigonometry). 120 seconds is 2 minutes, not 1.2 minutes or 1min 20secs.

• yeah so it would be nice to program base 60 in javascript. I just can't do that with the (number).toString(base).

• Originally Posted by caters
yeah so it would be nice to program base 60 in javascript. I just can't do that with the (number).toString(base).
The sexagesimal system as used in ancient Mesopotamia was not a pure base-60 system, in the sense that it did not use 60 distinct symbols for its digits.

• no but every place value was a power of 60 and so in that sense it is a pure base 60.

• With a base 10 subbase. There is a difference between the primary base which is the number that all place values are a power of and a subbase which is for the symbols. Like a japanese abacus uses base 10 with 5 as a subbase. Well the babylonians used base 60 with a base 10 subbase.

•

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•