Coding a Hex Value

  • Thread starter Herbert C. Brown, Jr.
  • Start date
H

Herbert C. Brown, Jr.

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.
 
E

Evertjan.

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>
 
R

Richard Cornford

Herbert said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top