# Ascii to Decimal

**URL:** https://discourse.nodered.org/t/ascii-to-decimal/52965
**Category:** General
**Created:** [30 October 2021 07:08 UTC](https://discourse.nodered.org/t/ascii-to-decimal/52965 "2021-10-30T07:08:53Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![New2Node](https://avatars.discourse-cdn.com/v4/letter/n/f1d935/32.png) [@New2Node](https://discourse.nodered.org/u/New2Node)
#### Post date: [30 October 2021 07:08 UTC](https://discourse.nodered.org/t/ascii-to-decimal/52965/1 "2021-10-30T07:08:53Z")

</div>

Hi,

Does anyone have a function that converts an ascii string to decimal (string)?

So if pass “ABCD1” into the function the output would be “65” “66” “67” “68” “49”

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [30 October 2021 08:12 UTC](https://discourse.nodered.org/t/ascii-to-decimal/52965/2 "2021-10-30T08:12:44Z")

</div>

Use a function node.

```auto
const stringToConvert = msg.payload;
msg.payload = getCharCodes(stringToConvert).join(" ");
return msg;
function getCharCodes(s){
    let charCodeArr = [];
    
    for(let i = 0; i < s.length; i++){
        let code = s.charCodeAt(i);
        charCodeArr.push(code);
    }
    
    return charCodeArr;
}

```

Proof...  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/a/da06cbaff953d435d9e98b6a526d88d76bded104.png)

> [@New2Node](#):
>
> output would be “65” “66” “67” “68” “49”

Do you really want a string of quotes and numbers? or did you want an array of strings???

---

<div class="post-metadata">

### Author: ![New2Node](https://avatars.discourse-cdn.com/v4/letter/n/f1d935/32.png) [@New2Node](https://discourse.nodered.org/u/New2Node)
#### Post date: [30 October 2021 08:39 UTC](https://discourse.nodered.org/t/ascii-to-decimal/52965/3 "2021-10-30T08:39:36Z")

</div>

Legend this is exactly what I needed!!! Much appreciated!

---

<div class="post-metadata">

### Author: ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)
#### Post date: [31 October 2021 00:52 UTC](https://discourse.nodered.org/t/ascii-to-decimal/52965/4 "2021-10-31T00:52:35Z")

</div>

or take advantage of nodejs Buffer  
`msg.payload = Buffer.from(msg.payload, 'ascii').join(" ")`

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [14 November 2021 00:53 UTC](https://discourse.nodered.org/t/ascii-to-decimal/52965/5 "2021-11-14T00:53:26Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
