bigInteger.js 라이브러리를 사용하여 160 비트 정수로 연산을 수행하려고하지만 16 진수로 표현하고 싶습니다. 형식으로 전송하여 ID로 사용할 수 있습니다. 내가 to hex
가 in hex
와 동일하게하는 것이 필요문자열로 표시된 10 진수를 16 진수 형식으로 변환하여 여전히 문자열로 표시합니다.
in hex 4044654fce69424a651af2825b37124c25094658
in dec 366900685503779409298642816707647664013657589336
to hex 366900685503779409298642816707647664013657589336
:
var git_sha1 = require('git-sha1');
var bigInt = require("big-integer");
var uuid = git_sha1((~~(Math.random() * 1e9)).toString(36) + Date.now());
console.log('in hex \t', uuid); // See the uuid I have
console.log('in dec \t', bigInt(uuid, 16).toString()); // convert it to bigInt and then represent it as a string
console.log('to hex \t', bigInt(uuid, 16).toString(16)); // try to convert it back to hex
여기 내 출력됩니다. 어떤 제안? 고맙습니다!
의 PR로 고정되었다 :(HTTPS : //github.com/peterolson/BigInteger.js/blob/master/BigInteger.js#L317-L331 의미는 'monkey patch it', dec의 문자열을 16 진수로 변환하는 방법입니다. –
그 크기의 숫자에 대해서는 확실하지 않지만 다음을 시도해보십시오. http://stackoverflow.com/questions/57803/how-to-convert-decimal-to-hex-in-javascript – CompanyDroneFromSector7G