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. ## Adding characters - not concatenating

Is there a way to convert back and forth from the ordinal value of a character to get a new value instead of the default concatination? In other words:

'a' + 5 = 'f'

not 'a' + 5 = 'a5'

• var str=String.fromCharCode(5+('a').charCodeAt());

• Thanks liorean! That's it!

THANK YOU!!!

• i was thinking math not characters Ive deleted it anyway. Cheers

• Code:
```String.prototype.hexAdd = function()
{
var arg, i = 0, sum = parseInt( this, 16 );
while( arg = parseInt( arguments[i++], 16 ) )
{
sum += arg;
}
return sum.toString( 16 );
}

var a = 'a';

var b = 4;

• How does parseInt handle radices different from 2...10,12,16? (Those that are even slightly probably to occur...)

For example, how does it handle 40? (or any other value higher than the amount of numbers and letters total in English language?)

• If the passed value i not part of the target radix, then NaN is returned, such as

parseInt( 'f', 2 );

http://devedge.netscape.com/library/...s.html#1008379

• i believe radices higher than 36 either return an error, or are ignored, and treated as 10

• That was given - but read this: "For radixes above ten, the letters of the alphabet indicate numerals greater than nine." How does it handle radices when the radix is greater than what /0-9a-z/ covers?

• Oh, I see what you mean. Just returns NaN.

• To answer that question (at least in mozilla's implementation), radix can only be 2...36 - other values always return NaN. toString with a radix above 36 gives this error, though:
Source File: javascript: (100).toString(37);
Line: 1

•

#### Posting Permissions

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