471,086 Members | 1,114 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,086 software developers and data experts.

encode a number in a javascript string

Hi,

I try to make up a javascript string which contains numeric numbers in
any positions. For example, I want to make a string: secretcode, where
secretcode.charAt(0)==(-21), secretcode.charAt(5)==(-14). Is there any
way to accomplish this task?

Thanks in advance,

Peter
Jul 23 '05 #1
3 2502
pk*****@yahoo.com (Peter) wrote in
news:aa*************************@posting.google.co m:
Hi,

I try to make up a javascript string which contains numeric numbers in
any positions.


Why? Password garbage?
--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
Jul 23 '05 #2
pk*****@yahoo.com (Peter) writes:
I try to make up a javascript string which contains numeric numbers
Are there any other? :)
in any positions. For example, I want to make a string: secretcode,
where secretcode.charAt(0)==(-21), secretcode.charAt(5)==(-14). Is
there any way to accomplish this task?


If you can avoid negative numbers, or numbers above 65535, then it's
easy:
var encode = String.fromCharCode(65,66,10,2045,1023,65530);
alert([encode.charCodeAt(0),
encode.charCodeAt(1),
encode.charCodeAt(2),
encode.charCodeAt(3),
encode.charCodeAt(4),
encode.charCodeAt(5)]);

if you have to store negative numbers as well, but no more than 32767
or less than -32768, then you can just add 32768 to the number before
storing it.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #3
pk*****@yahoo.com (Peter) wrote in message news:<aa*************************@posting.google.c om>...
Hi,

I try to make up a javascript string which contains numeric numbers in
any positions. For example, I want to make a string: secretcode, where
secretcode.charAt(0)==(-21), secretcode.charAt(5)==(-14). Is there any
way to accomplish this task?

Thanks in advance,

Peter

Hi..
Be a little bit more concise...
You said first "numeric numbers in any positions" and then, the
example refers to precise indexes, like 0 and 5....
These indexes should be fixed or not?
What rule do you want your strings to follow?
S.
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Scott Matthews | last post: by
7 posts views Thread by Richard Trahan | last post: by
1 post views Thread by ok | last post: by
7 posts views Thread by sarada7 | last post: by
5 posts views Thread by Oleg.Ogurok | last post: by
6 posts views Thread by 7stud | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.