Path: csiph.com!weretis.net!feeder8.news.weretis.net!news.mb-net.net!open-news-network.org!.POSTED.178.197.216.189!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: Decimal numeric string to hexadecimal numeric string? Date: Thu, 01 Jul 2021 00:51:08 +0200 Organization: PointedEars Software (PES) Lines: 36 Message-ID: <20837730.9tcgPO3Tcr@PointedEars.de> References: <233183ba-98dc-47d5-84f6-bd3beef1e793n@googlegroups.com> <87fsxegmpj.fsf@bsb.me.uk> Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit Injection-Info: gwaiyur.mb-net.net; posting-host="178.197.216.189"; logging-data="31527"; mail-complaints-to="abuse@open-news-network.org" User-Agent: KNode/4.14.10 Cancel-Lock: sha1:6ufBRkdsdvh28lOKYuMfpW3DDEg= X-User-ID: U2FsdGVkX18bQMGisYSZHu1F1VebPhyukQmX4kfYt4OrQMysVXawKQ== X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. Jonas Thörnvall writes: >> fredag 18 juni 2021 kl. 14:59:24 UTC+2 skrev sc...@sauyet.com: >>> Jonas Thornvall wrote: >>> > prgNbr="11" >>> > >>> > parseInt(prgNbr); >>> > prgNbr.toInteger(16); Neither of these statements do anything useful as the argument is a primitive value that cannot be modified. >>> What are you trying to do? >> >> A numeric "decimal" string to hexdecimal string. >> So Michales suggestion did not work out, it gives a hexadecimal number >> not string. > > parseInt(prgNbr).toString(16) > > Technically, parseInt(prgNbr, 16) doesn't give a hexadecimal number > (there is not such thing). It gives a number by interpreting the string > as hexadecimal digits. Instead: let hex = parseInt(prgNbr, 10).toString(16); parseInt() should not be called without a radix value because then the interpretation of the string depends on its prefix. This is a FAQ. -- PointedEars FAQ: | | Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.