How to use the fromString function from long
Find comprehensive JavaScript long.fromString code examples handpicked from public code repositorys.
long.fromString() is a method in the Long.js library that converts a string representation of a long integer into a Long object.
253 254 255 256 257 258 259 260 261 262
var MAX_CONSTANT = 16; var longRadix = [null, null, Long.fromString('4000000000000000',16), Long.fromString('383d9170b85ff80b',16), Long.fromString('4000000000000000',16), Long.fromString('6765c793fa10079d',16), Long.fromString('41c21cb8e1000000',16), Long.fromString('3642798750226111',16), Long.fromString('1000000000000000',16), Long.fromString('12bf307ae81ffd59',16), Long.fromString( 'de0b6b3a7640000',16), Long.fromString('4d28cb56c33fa539',16), Long.fromString('1eca170c00000000',16), Long.fromString('780c7372621bd74d',16), Long.fromString('1e39a5057d810000',16), Long.fromString('5b27ac993df97701',16),
+ 35 other calls in file
GitHub: EOSIO/eosjs-secp256k1
26 27 28 29 30 31 32 33 34 35
function commit(blindFactor, value) { if(!blindFactor || blindFactor.length !== 32) throw new TypeError('blindFactor is a required 32 byte array') const commitment = malloc(33) const valueLong = Long.fromString(String(value), true) const ret = Module.ccall( 'secp256k1_pedersen_commit', 'number', ['number', 'number', 'number', 'number', 'number'], [ctx(), commitment, charStar(blindFactor), valueLong.low, valueLong.high]
+ 5 other calls in file
How does long.fromString work?
long.fromString()
is a method in the Long.js library that takes a string representation of a 64-bit signed integer and converts it to a Long object, allowing the number to be manipulated in JavaScript.
It uses the string representation to create two 32-bit values that are combined into a single 64-bit value, using two's complement representation to handle negative values.
218 219 220 221 222 223 224 225 226 227
function signTX(ccId, fcn, arg, msg, counter, inkLimit, priKey) { let args = []; let senderAddress = ethUtils.privateToAddress(new Buffer(priKey, "hex")); let senderSpec = { sender: Buffer.from(settingsConfig.AddressPrefix + senderAddress.toString("hex")), counter: Long.fromString(counter.toString()), ink_limit: Buffer.from(inkLimit), msg: Buffer.from(msg) }; args.push(Buffer.from(fcn ? fcn : 'invoke', 'utf8'));
133 134 135 136 137 138 139 140 141 142
blinder.length !== 32 ) throw new TypeError('blinder must be a Uint8Array of 32 bytes'); const output = malloc(33); const valueLong = Long.fromString(value, true); const ret = Module.ccall( 'pedersen_commitment', 'number',
+ 3 other calls in file
Ai Example
1 2 3
const Long = require("long"); const longValue = Long.fromString("9223372036854775807"); // create a Long from a string console.log(longValue); // output: Long { low: -1, high: 2147483647, unsigned: false }
In this example, we first require the long module and create a new Long object using the fromString method. We pass in a string representation of a large number, which is converted to a Long object. Finally, we log the Long object to the console to see its value.
108 109 110 111 112 113 114 115 116 117
Long.fromString('1e39a5057d810000',16), Long.fromString('5b27ac993df97701',16), Long.fromString('1000000000000000',16), Long.fromString('27b95e997e21d9f1',16), Long.fromString('5da0e1e53c5c8000',16), Long.fromString( 'b16a458ef403f19',16), Long.fromString('16bcc41e90000000',16), Long.fromString('2d04b7fdd9c0ef49',16), Long.fromString('5658597bcaa24000',16), Long.fromString( '6feb266931a75b7',16), Long.fromString( 'c29e98000000000',16), Long.fromString('14adf4b7320334b9',16), Long.fromString('226ed36478bfa000',16), Long.fromString('383d9170b85ff80b',16), Long.fromString('5a3c23e39c000000',16), Long.fromString( '4e900abb53e6b71',16), Long.fromString( '7600ec618141000',16), Long.fromString( 'aee5720ee830681',16), Long.fromString('1000000000000000',16), Long.fromString('172588ad4f5f0981',16),
+ 89 other calls in file
283 284 285 286 287 288 289 290 291 292
featureFlagDataContractBlockHeight: asFunction(() => { if (options.FEATURE_FLAGS_CONTRACT_BLOCK_HEIGHT === undefined || options.FEATURE_FLAGS_CONTRACT_BLOCK_HEIGHT === '') { return new Long(); } return Long.fromString(options.FEATURE_FLAGS_CONTRACT_BLOCK_HEIGHT); }), }); /**
19 20 21 22 23 24 25 26 27 28 29
// This is a safe integer in JS return intValue; } const signed = value.startsWith("-"); const long = Long.fromString(value, !signed); return [long.getLowBits(), long.getHighBits(), signed]; }; denormalizers[IndexKeyEncoder.Type.Boolean] = (value) => value === "true"; denormalizers[IndexKeyEncoder.Type.Single] = (value) => parseFloat(value);
129 130 131 132 133 134 135 136 137 138
* ``` */ proto.writeLong = function (val) { if (typeof val === 'string') { if (!utility.isSafeNumberString(val)) { val = Long.fromString(val); } else { val = Number(val); } } else if (Long.isLong(val) && (val.high === 0 || val.high === -1)) {
89 90 91 92 93 94 95 96 97 98
} buildLoginRequest() { const androidId = this.auth.androidId; const securityToken = this.auth.securityToken; const LoginRequestType = PushClient.proto.lookupType("mcs_proto.LoginRequest"); const hexAndroidId = Long.fromString(androidId).toString(16); const loginRequest = { adaptiveHeartbeat: false, authService: 2, authToken: securityToken,
+ 4 other calls in file
11 12 13 14 15 16 17 18 19 20
const signed64 = number => new Encoder().writeVarLong(number).buffer const decode64 = buffer => new Decoder(buffer).readVarLong() const B = (...args) => Buffer.from(args) const L = value => Long.fromString(`${value}`) describe('writeEncoder', () => { it('should throw if the value is not an Encoder', () => { const encoder = new Encoder()
197 198 199 200 201 202 203 204 205 206
return j.or(long.fromNumber(Math.random() * 16383.0).shiftLeft(48)).toString(); } function GeneratePXUUID(mostSignificantBits, leastSignificantBits) { let uuidMostSignificantBytes = long.fromString(mostSignificantBits).toBytes().reverse(); let uuidLeastSignificantBytes = long.fromString(leastSignificantBits).toBytes().reverse(); let map = [
+ 3 other calls in file
62 63 64 65 66 67 68 69 70 71
qrem.should.eql(-2037446008); // var product,difference,carry; product = Long.fromString('1983905792',10); difference = Long.fromString('-1673294219', 10); // console.log(product.shiftRight(32).low, difference.low >>>32, ~product.low >>> 32, '====', Long.fromNumber(difference.low >>>32).compare(Long.fromNumber(~product.low >>> 32))); carry = Long.fromNumber( product.shiftRight(32).low ).add( Long.fromNumber(difference.low >>>32).compare(Long.fromNumber(~product.low >>> 32)) > 0 ? Long.fromInt(1) : Long.fromInt(0)
+ 10 other calls in file
GitHub: elshor/dstwitter
55 56 57 58 59 60 61 62 63 64
params.cursor = res.next_cursor_str; return twitterPage.call( this,keys, wrapped, endpoint,property, params, pageCount, left, upToNow,reporter); }else if(typeof thisPage[0].id_str === 'string'){ params.max_id = Long.fromString(thisPage[thisPage.length-1].id_str).sub(1).toString(); return twitterPage.call( this,keys, wrapped, endpoint, property, params, pageCount, left, upToNow, reporter); }else{ reporter();
235 236 237 238 239 240 241 242 243 244 245 246 247
//from aoa_ssa this.format = '<Q'; // var ui64 = Long.fromNumber(93372036854775807, true); // fails and is clearly a bug in the Long library var ui64 = Long.fromString('93372036854775807', true,10); // passes and is an ok workaround // according to the internet 93372036854775807 = 00000001 01001011 10111001 01011111 01110000 10101110 11111111 11111111 // which means the LOW 32bits are: 01110000 10101110 11111111 11111111
+ 3 other calls in file
GitHub: Fslink32/pmrv2
6451 6452 6453 6454 6455 6456 6457 6458 6459
if (radix < 2 || 36 < radix) { throw(new Error('radix out of range: ' + radix)); } if (str.charAt(0) == '-') { return Long.fromString(str.substring(1), unsigned, radix).negate(); } else if (str.indexOf('-') >= 0) { throw(new Error('number format error: interior "-" character: ' + str)); }
+ 12 other calls in file
GitHub: lukyy8/discord.js-hakai
1669 1670 1671 1672 1673 1674 1675 1676 1677 1678
*/ _sortPositionWithID(collection) { return collection.sort((a, b) => a.position !== b.position ? a.position - b.position : Long.fromString(b.id).sub(Long.fromString(a.id)).toNumber() ); } }
+ 3 other calls in file
GitHub: titansys/push-receiver
113 114 115 116 117 118 119 120 121 122
chromeVersion : '63.0.3234.0', channel : 1, }, }, version : 3, id : androidId ? Long.fromString(androidId) : undefined, securityToken : securityToken ? Long.fromString(securityToken, true) : undefined, };
2196 2197 2198 2199 2200 2201 2202 2203 2204 2205
while ((b & 0x80) !== 0) { b = this._buffer.readBits(8); // result |= (b & 0x7f) << bits; // Bitwise operators do not work above 32 bits var myLong = new Long; myLong = Long.fromString(result.toString(), false); result = myLong.or((b & 0x7f) * Math.pow(2,bits)).toString(); bits += 7; } result = parseInt(result.toString());
long.default is the most popular function in long (905 examples)