encode a number in a javascript string

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter

    #1

    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.char At(0)==(-21), secretcode.char At(5)==(-14). Is there any
    way to accomplish this task?

    Thanks in advance,

    Peter
  • John Bokma

    #2
    Re: encode a number in a javascript string

    pku8205@yahoo.c om (Peter) wrote in
    news:aa7f2aac.0 409240655.297a1 4b@posting.goog le.com:
    [color=blue]
    > Hi,
    >
    > I try to make up a javascript string which contains numeric numbers in
    > any positions.[/color]

    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

    Comment

    • Lasse Reichstein Nielsen

      #3
      Re: encode a number in a javascript string

      pku8205@yahoo.c om (Peter) writes:
      [color=blue]
      > I try to make up a javascript string which contains numeric numbers[/color]

      Are there any other? :)
      [color=blue]
      > in any positions. For example, I want to make a string: secretcode,
      > where secretcode.char At(0)==(-21), secretcode.char At(5)==(-14). Is
      > there any way to accomplish this task?[/color]

      If you can avoid negative numbers, or numbers above 65535, then it's
      easy:
      var encode = String.fromChar Code(65,66,10,2 045,1023,65530) ;
      alert([encode.charCode At(0),
      encode.charCode At(1),
      encode.charCode At(2),
      encode.charCode At(3),
      encode.charCode At(4),
      encode.charCode At(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 - lrn@hotpop.com
      DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
      'Faith without judgement merely degrades the spirit divine.'

      Comment

      • simina

        #4
        Re: encode a number in a javascript string

        pku8205@yahoo.c om (Peter) wrote in message news:<aa7f2aac. 0409240655.297a 14b@posting.goo gle.com>...[color=blue]
        > 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.char At(0)==(-21), secretcode.char At(5)==(-14). Is there any
        > way to accomplish this task?
        >
        > Thanks in advance,
        >
        > Peter[/color]


        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.

        Comment

        Working...