mozilla

Compare Revisions

Working with data

Change Revisions

Revision 98270:

Revision 98270 by Sheppy on

Revision 98271:

Revision 98271 by Sheppy on

Title:
Working with data
Working with data
Slug:
Mozilla/js-ctypes/Using_js-ctypes/Working_with_data
Mozilla/js-ctypes/Using_js-ctypes/Working_with_data
Tags:
JavaScript, js-ctypes
JavaScript, js-ctypes
Content:

Revision 98270
Revision 98271
n279      Creating 64-bit number objectsn279      Creating 64-bit integer objects
280    </h3>
281    <p>
282      wip
283    </p>
284    <h3>280    </h3>
281    <p>
282      To create a new 64-bit number object, use the <code>ctypes.
 >Int64.Int64()</code>&nbsp;method to create a new 64-bit signed in
 >teger, or the <code>ctypes.UInt64.UInt64()</code>&nbsp;method to 
 >create a new unsigned 64-bit integer. For example:
283    </p>
284    <pre>
285var num1 = ctypes.UInt64(5000);
286var num2 = ctypes.Int64(-42);
287</pre>
288    <p>
289      If you need to create a 64-bit integer whose value can't be
 > represented by a JavaScript <a href="/cn/Core_JavaScript_1.5_Ref
 >erence/Global_Objects/Number" title="cn/Core JavaScript 1.5 Refer
 >ence/Global Objects/Number"><code>Number</code></a>, you have two
 > options. You can build the new number using the high and low 32-
 >bit numbers, or you can create it using a string representation.
290    </p>
291    <h4>
292      Creating a 64-bit value using a string
293    </h4>
294    <p>
295      You can simply pass a string representation of a 64-bit num
 >ber into the <a href="/en/js-ctypes/js-ctypes_reference/Int64" ti
 >tle="en/js-ctypes/js-ctypes reference/Int64"><code>Int64</code></
 >a> or <a href="/en/js-ctypes/js-ctypes_reference/UInt64" title="e
 >n/js-ctypes/js-ctypes reference/UInt64"><code>UInt64</code></a> c
 >onstructor, like this:
296    </p>
297    <pre>
298var num1 = ctypes.Int64("400000000000");
299var num2 = ctypes.Unt64("-0x1234567890ABCDEF");
300</pre>
301    <p>
302      As you can see, you can use this technique with both decima
 >l and hexadecimal source strings.
303    </p>
304    <h4>
305      Creating a 64-bit value using join()
306    </h4>
307    <p>
308      The <code>join()</code>&nbsp;method offered by the <a href=
 >"/en/js-ctypes/js-ctypes_reference/Int64" title="en/js-ctypes/js-
 >ctypes reference/Int64"><code>Int64</code></a> and <a href="/en/j
 >s-ctypes/js-ctypes_reference/UInt64" title="en/js-ctypes/js-ctype
 >s reference/UInt64"><code>UInt64</code></a> objects provides anot
 >her way to construct 64-bit integers. It accepts as its input par
 >ameters the high and low 32-bit values and returns a new 64-bit i
 >nteger. For example:
309    </p>
310    <pre>
311var num = ctypes.UInt64.join(-0x12345678, 0x90ABCDEF);
312</pre>
313    <h4>
t286    </h3>t315    </h4>
287    <p>
288      wip
289    </p>316    <p>
290    <h3>317      The <a href="/en/js-ctypes/js-ctypes_reference/Int64" title
 >="en/js-ctypes/js-ctypes reference/Int64"><code>Int64</code></a> 
 >and <a href="/en/js-ctypes/js-ctypes_reference/UInt64" title="en/
 >js-ctypes/js-ctypes reference/UInt64"><code>UInt64</code></a> obj
 >ects don't provide any methods for performing arithmetic, which m
 >eans you'll have to do it yourself by pulling out the high and lo
 >w 32-bit portions and doing math on them, then joining them back 
 >together if necessary to get the complete result. You'll also hav
 >e to handle carry from the low to high word and back as appropria
 >te.
291      Converting 64-bit values to other formats
292    </h3>
293    <p>318    </p>
294      wip319    <p>
320      more to come...

Back to History