473,396 Members | 2,082 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 2639
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Scott Matthews | last post by:
I've recently come upon an odd Javascript (and/or browser) behavior, and after hunting around the Web I still can't seem to find an answer. Specifically, I have noticed that the Javascript...
4
by: Newbie | last post by:
How would I modify this form to encode *all* the characters in the 'source' textarea to the '%xx' format & place result code into the 'output' textarea? (cross browser compatable) Any help is...
7
by: Richard Trahan | last post by:
I need a javascript function to hex-encode a plus sign so I can pass the plus sign as an argument in a GET request. escape() and encodeURI() don't do it (and probably shouldn't, because '+' is a...
1
by: ok | last post by:
I think my last question was not clear, so people gave me the reverse answer. I want to put a string in an html file, and human eyes or robots will not be able to read it. For example I want...
7
by: sarada7 | last post by:
Hi, Is there a way to encode/decode HTML using C++?? Thanks, Sarada.
5
by: Oleg.Ogurok | last post by:
Hi there, I need to encode the value of an XML attribute, e.g. string myXml = "<element myAttr=\"" + encodeURIComponent("my \"value") + "\"" ...."; Is there an equivalent of...
6
by: 7stud | last post by:
s1 = "hello" s2 = s1.encode("utf-8") s1 = "an accented 'e': \xc3\xa9" s2 = s1.encode("utf-8") The last line produces the error: --- Traceback (most recent call last):
13
by: mario | last post by:
Hello! i stumbled on this situation, that is if I decode some string, below just the empty string, using the mcbs encoding, it succeeds, but if I try to encode it back with the same encoding it...
4
by: J Peyret | last post by:
Well, as usual I am confused by unicode encoding errors. I have a string with problematic characters in it which I'd like to put into a postgresql table. That results in a postgresql error so I...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.