Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.lang.javascript Subject: Re: How do I convert the following to Uint8Array. Date: Fri, 22 Jan 2016 12:41:01 +0000 Organization: A noiseless patient Spider Lines: 21 Message-ID: <87y4bhwzvm.fsf@bsb.me.uk> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="017616aa25f81ec581c44d76d61ba2f3"; logging-data="18895"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+T2h/QlHcQceO08i1SsiYugQoe9kVEHdU=" Cancel-Lock: sha1:shutUXU8I8iNPZ/nyvagC+vsSM4= sha1:G45uC2Tnjap6y8jVjJ0vLI4I9AA= X-BSB-Auth: 1.bfffb2ed62e0cf0b2cc9.20160122124101GMT.87y4bhwzvm.fsf@bsb.me.uk Xref: csiph.com comp.lang.javascript:29405 Robby Balona writes: > I am new to javascript. I have been trying to figure this out for a > week now and because I don't know what I am talking about .. its hard > to Google the right solution. > > I have a string "ab05d705" and I am trying to convert it to the > following so I can add it to a Uint8Array. So how do I convert the > string "ab05d705" to > 0xab,0x05,0xd7,0x05 to put into the following > var data = new Uint8Array([0xab,0x05,0xd7,0x05]); One way: var s = "ab05d705"; Uint8Array.from(s.replace(/../g, ',0x$&').split(',').slice(1)) Try each part out one at a time to see what this is doing. -- Ben.