Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Coding a Hex Value

Reply
Thread Tools

Coding a Hex Value

 
 
Herbert C. Brown, Jr.
Guest
Posts: n/a
 
      08-19-2007
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.
http://www.velocityreviews.com/forums/(E-Mail Removed)


 
Reply With Quote
 
 
 
 
Evertjan.
Guest
Posts: n/a
 
      08-19-2007
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)
 
Reply With Quote
 
 
 
 
Richard Cornford
Guest
Posts: n/a
 
      08-19-2007
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
hex string to hex value tim Python 8 11-23-2005 06:27 PM
[Fwd: Re: hex string to hex value] tim Python 2 11-23-2005 07:18 AM
Hex Color Codes - Hex 6 <=> Hex 3 lucanos@gmail.com HTML 10 08-18-2005 11:21 PM
hex value in string back to real hex value jack Python 4 09-08-2004 07:11 AM
hex(-5) => Futurewarning: ugh, can't we have a better hex than '-'[:n<0]+hex(abs(n)) ?? Bengt Richter Python 6 08-19-2003 07:33 AM



Advertisments