Coding a Hex Value

Discussion in 'Javascript' started by Herbert C. Brown, Jr., Aug 19, 2007.

  1. To whomever may assist,

    I am trying to code an index (TLE - Tagged Logical Element) identifier to
    load a customer statement into OnDemand (an archival system created by IBM).
    The TLE is defined as such:

    idx = new index();
    tle = new String("AcctNumber"); <!-- AcctNumber is an array that can
    have one or more values -->
    tle.name = 'AcctNo';
    tle.sequence = "\x80\x0A\x7F\xFF\xFF\xFF\xFF\xFF";
    tle.level = "\xFF\xFF"

    My issue is whether the syntax of "\x80" is the correct format to code a hex
    value. Any assistance would be appreciated.
    --

    Herbert C. Brown, Jr.
    Herbert C. Brown, Jr., Aug 19, 2007
    #1
    1. Advertising

  2. Herbert C. Brown, Jr.

    Evertjan. Guest

    Herbert C. Brown, Jr. wrote on 19 aug 2007 in comp.lang.javascript:

    > To whomever may assist,


    Wow, are we correcr, Junior,

    > I am trying to code an index (TLE - Tagged Logical Element) identifier
    > to load a customer statement into OnDemand (an archival system created
    > by IBM). The TLE is defined as such:
    >
    > idx = new index();


    Is that Javascript?
    [anyway, you do not use idx here,
    so it cannot be amn important part of your Q.]

    > tle = new String("AcctNumber");


    Use:

    var tle = ...

    <!-- AcctNumber is an array that can have one or more values -->

    No, "AcctNumber" is a litteral string, not an array.

    > tle.name = 'AcctNo';


    wouldn't you prefer to use an oblect?

    > tle.sequence = "\x80\x0A\x7F\xFF\xFF\xFF\xFF\xFF";


    This is just applying a litteral string again.

    > tle.level = "\xFF\xFF"
    >
    > My issue is whether the syntax of "\x80" is the correct format to code
    > a hex value. Any assistance would be appreciated.


    \xnn is a way to enter ascii characters, as \unnnn is to enter Unicode
    characters.

    Remember, the characters are two bytes long in bothe methods.

    <script type='text/javascript'>

    var ascii = '\x48\x65\x6c\x6c\x6f';
    var unico = '\u0048\u0065\u006c\u006c\u006f';

    alert(ascii);
    alert(unico);
    alert(ascii == unico);
    alert(ascii === unico);

    </script>

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Aug 19, 2007
    #2
    1. Advertising

  3. Herbert C. Brown, Jr. wrote:
    > To whomever may assist,
    >
    > I am trying to code an index (TLE - Tagged Logical Element)
    > identifier to load a customer statement into OnDemand (an
    > archival system created by IBM).


    That is all fine and good, but is too far detached from anything
    directly related javascript and its use to be of any help. And it
    certainly is doing nothing to explain the what and why of the code you
    have posted.

    > The TLE is defined as such:
    >
    > idx = new index();
    > tle = new String("AcctNumber"); <!-- AcctNumber is an array
    > that can have one or more values -->


    Javascript has end-of-lien and multi-line comment syntaxes, which should
    be the only comment syntaxes used to comment javascript.

    The comment here is false. I can see the quote marks around AcctNumber
    and so I can see that it is a string literal not an Array.

    > tle.name = 'AcctNo';
    > tle.sequence = "\x80\x0A\x7F\xFF\xFF\xFF\xFF\xFF";
    > tle.level = "\xFF\xFF"
    >
    > My issue is whether the syntax of "\x80" is the correct format
    > to code a hex value. Any assistance would be appreciated.


    The problem here is that "to code a hex value" has little meaning in
    javascript. The source code character sequence - \xNN -(where NN are two
    characters from the digits 0 to 9 and the letters A, B, C, D, E and F
    (in upper or lower case)), when they appear in a string literal or
    regular expression literal, are a Hex escape sequence that defines the
    character code (16 bit Unicode code point) of the character that will be
    used in the sting or regular expression in place of the escape sequence.
    However you go about defining the characters used in a string literal
    the string primitive value that is the result is just (and only) a
    sequence of 16 bit Unicode code points.

    (Note: Hex escape sequences in string literals and regular expression
    literals are a left-over from before javascript was standardised to use
    16 bit Unicode code points in its string literals, and Unicode escape
    sequences now exist (in the form \uNNNN) to allow the rest of (all of)
    the code points to be expressed as escape sequences.)

    Numeric literals may also be expressed in Hexadecimal, in the form:-

    var n = 0xE4A2; //the number of hex digits used can vary considerably

    - but the result is a numeric value that is a 64 bit IEEE double
    precision floating point number (even if that number represents an
    integer). (The handling (interpretation of and translation into IEEE
    double precision floats) of HexIntegerLiteral numeric literals is
    defined in ECMA 262, 3rd Ed. Section 7.8.3).

    Generally javascript is not a language in which you work with (or think
    about) bit sequences or Hex values.

    Richard.
    Richard Cornford, Aug 19, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    10
    Views:
    6,191
    Neredbojias
    Aug 19, 2005
  2. Bengt Richter
    Replies:
    6
    Views:
    466
    Juha Autero
    Aug 19, 2003
  3. jack
    Replies:
    4
    Views:
    586
  4. tim

    hex string to hex value

    tim, Nov 22, 2005, in forum: Python
    Replies:
    8
    Views:
    18,851
  5. tim
    Replies:
    2
    Views:
    1,558
    Dennis Lee Bieber
    Nov 23, 2005
Loading...

Share This Page