[Question]
  [
# Task
Build a calculator, that takes any string, from a file, stdin or whatever, and adds up all the values of the chars.
Example
```
Input
Hello World!
Output
1085
```
# Rules
The calculator needs to accept just ASCII encoding.
The shortest code wins.
# Notes
Regarding to the comment of m.buettner, I need to say, I didn't thought of the multibyte part.  
So I leave it as a bonus thing aswell.  
The calculator should be run as written, so no need to modify before compiling or interpreting.
# Bonus
Thanks to [Synthetica](https://codegolf.stackexchange.com/users/18638/synthetica), here is one more bonus, 
> 
> The program that has the lowest output when you use its code as its input wins gets a star.
> 
> 
> 
I don't want to modify it completly.
If you write it additional to output the (right) value in UTF-8 you get a star.
The code that executes fastest on my Laptop (Lenovo Yoga 13 Intel Core i5 3317U 1.7Ghz, 8GB RAM, 128GB SSD, Intel HD 4000, Windows 8) gets a star.
Web codes will run first under IE11 with [chakra](http://en.wikipedia.org/wiki/Chakra_(JScript_engine)) and then in FireFox 29.0.1 with [SpiderMonkey](http://en.wikipedia.org/wiki/SpiderMonkey_(software))
Linux code will run on a Raspberry Pi with Raspbian.
The teststring is this:
```
q/%8hnp>T%y?'wNb\},9krW &D9']K$n;l.3O+tE*$*._B^s!@k\&Cl:EO1zo8sVxEvBxCock_I+2o6 yeX*0Xq:tS^f)!!7=!tk9K<6#/E`ks(D'$z$\6Ac+MT&[s[]_Y(`<g%"w%cW'`c&q)D$0#C$QGf>?A$iawvc,}`9!('`c&q)D$0#C$QGf>?A$iawvc,}`9!(
```
Have fun coding :)
# Bonusscoring
I plan to do the scoring at this Saturday so the 07.06.14, all answers after that date won't get bonus points ;)
You can download the code I gonna use for testing [here](https://github.com/DerKnerd/Application-Speedtest) feel free to fork and improve it :)
Little update because of the bonus, my laptop is partially broken so I will do it probably next weekend, I am really sorry for that :(
  
[Answer]
# GolfScript, 4 characters
```
{+}*
```
Simply uses the fold operator (`*`) to add up all the characters.
If it has to work with the empty string, 9 chars:
```
{{+}*}0if
```
Thanks to @PeterTaylor for providing an alternative 6-char version that works with empty string:
```
0\{+}/
```
[Answer]
# APL (8)
```
+/⎕UCS⍞
```
Explanation:
* `+/` sum of
* `⎕UCS` unicode values of
* `⍞` character input
[Answer]
# Haskell 36
```
main=interact$show.sum.map fromEnum
```
[Answer]
# Shell+GNU tools, 29 bytes
```
echo `od -An -tuC`|tr \  +|bc
```
Takes input from stdin:
```
$ printf "%s" 'Hello World!' | ./addchars.sh 
1085
$ 
```
Own score: 2385
---
# c, 52 bytes
```
c;main(p){while(~(p=getchar()))c+=p;printf("%d",c);}
```
Compile with (some warnings produced):
```
gcc addchars.c -o addchars
```
Takes input from stdin:
```
$ printf "%s" 'Hello World!' | ./addchars 
1085 $ 
```
Own score: 4354
[Answer]
# Javascript (*ES6*) 51
```
alert([...prompt(x=0)].map(y=>x+=y.charCodeAt())|x)
```
[Answer]
# 8086 Assembly (16-bit) - 47 41 bytes
The contents of the `test.com` file are:
```
98 01 c3 b4 01 cd 21 3c 0d 75 f5 89 c7 c6 05 24
89 d8 b1 0a 4f 31 d2 f7 f1 80 ca 30 88 15 09 c0
75 f2 89 fa b4 09 cd 21 c3
```
Actual work is done in the first 11 bytes; I need the rest to print the result in decimal notation.
Source code (give as input to the DOS `debug.com` assembler):
```
a
; input the string; count the sum
    cbw
    add bx, ax
    mov ah, 1
    int 21
    cmp al, d
    jne 100
; Prepare for output: stuff an end-of-line marker
    mov di, ax
    mov [di], byte 24
    mov ax, bx
    mov cl, a
; 114
; Divide by 10; write digits to buffer
    dec di
    xor dx, dx
    div cx
    or  dl, 30
    mov [di], dl
    or  ax, ax
    jne 114
; Print the string
    mov dx, di
    mov ah, 9
    int 21
    ret
rcx 29
n test.com
w
q
```
Some notes on the code:
* Only handles one line (up to end-of-line character 13); hangs if no end-of-line
* Only 7-bit characters are supported (results are incorrect otherwise)
* Outputs 0 for empty input
* Cannot handle output greater than 64K
* Instruction at address 0x10d overwrites itself (pure coincidence)
* Have to use DOS emulators like [DosBox](http://www.dosbox.com/) to assemble and run this program
[Answer]
# [gs2](https://github.com/nooodl/gs2/blob/master/gs2.py), 1 byte
```
d
```
`d` (`0x64` / `sum`), of course, sums up all bytes in standard input.
[Answer]
# CJam, 3 bytes (sum 260)
```
q1b
```
You can [try it online](http://cjam.aditsu.net/#code=q1b&input=Hello%20World!).  
Thanks jimmy23013 for helping chop off 2 characters :)
**Explanation:**
```
q     read the input into a string  
1b    convert from base 1, treating each character as its numeric value
```
[Answer]
## Ruby, ~~13~~ 12 bytes
```
p~9+gets.sum
```
`sum` is a built-in function that sums the characters of a string. Subtracts 10 to account for the newline at the end of `gets`'s return value.
(Edited 4 years later to change `x-10` to `~9+x`... the value of `~9` is `-10`, but it lets us remove the space between `p` and its argument, saving a byte.)
[Answer]
# Python 3 - 28 bytes
```
print(sum(map(ord,input())))
```
Example run:
```
$ ./sum_string.py <<< 'Hello World!'
1085
```
Gets input from stdin, `map`s the `ord` function to it to get the ASCII value of each character, `sum`s it and `print`s.
[Answer]
## Befunge98, 6 bytes, sum: 445
```
2j@.~+
```
Any interpreter should be fine. I use [CCBI](http://users.tkk.fi/~mniemenm/befunge/ccbi.html).
Use as follows:
```
printf 'Hello World!' | ccbi calc.fg
```
Works for multibyte chars and empty strings.
**Explanation**
* `2j` - jump over the next two instructions (`@` and `.` - see below)
* `~` - put the next char on the stack
* `+` - add the code value of the new char to the current sum. The instruction pointer wraps to the beginning and the cycle repeats
* when `~` encounters an EOF it inverses the direction of the pointer and the two "hidden" instructions are executed:
* `.` - print the sum
* `@` - exit
[Answer]
# Python, 24 bytes
This is shorter than any Python solution so far: an unnamed anonymous function, which takes the string as an argument, and returns the sum.
```
lambda x:sum(x.encode())
```
[**Try it online!**](https://tio.run/nexus/python3#@59mm5OYm5SSqFBhVVyaq1Ghl5qXnJ@SqqGp@b@gKDOvRCNNQ8kjNScnXyE8vygnRVEJKAEA)
First, `x.encode()` transforms it into a `bytes` object. Then, `sum` adds the char-code values. As this is a lambda function, the value is implicity returned.
Additionally, one could have `lambda x:sum(map(ord,x))` for the same byte count.
[Answer]
## PowerShell - 27
```
[char[]]$args[0]|measure -s
```
**Example**
```
> SumChars.ps1 'Hello World!'
Count    : 12
Average  : 
Sum      : 1085
Maximum  : 
Minimum  : 
Property : 
```
[Answer]
# Julia - ~~11~~ 7 characters, resultant sum = ~~943~~ 536
Since the question allows the input to come from whatever source you want, I choose an existing variable. Assume that `A` contains the string we wish to evaluate.
```
sum(A)1
```
As it turns out, you can sum the string directly, and it will evaluate... however, due to the way that summing of chars is handled, if there is an odd number of characters in the string, it will output a character, rather than an integer of any sort. As such, we force it to cast to int by multiplying by 1.
Old version:
```
sum(A.data)
```
Will output in a hexadecimal notation (if the sum is less than 256, it'll be `0x??`, otherwise it'll be 8 byte as `0x????????`). If used in code where the result is used, it will operate just like any other number (it's just how Julia displays unsigned ints).
To see the value of the result in decimal, enclose the above in `int()`, as in `int(sum(A.data))`.
For anybody who doesn't know Julia, you assign to `A` exactly the same way you do other assignments to variables. So, `A="Hello World!"` or `A="sum(n.data)"`. In the case where you need to put in `"` or `'` characters, there are multiple options, the easiest of which (because it avoids need for knowledge of the nuances of Julia string literals) is `A=readline()`, followed by simply typing in the string into STDIN (won't handle newlines, though). The escape sequence for newline is, as usual, `\n`, but I don't believe you can use that with readline().
[Answer]
# K5, 2 bytes (function), 5 bytes (program)
## Function
```
+/
```
## Program
```
+/0:`
```
Not sure if K5 was created before or after this challenge was posted. Regardless...THIS IS AWESOME!!
In K5, if you perform arithmetic operations on strings, it converts the characters to their ASCII codes. So this just uses the sum operator `+/` (actually, it's plus + over).
[Answer]
# Matlab/Octave 4 bytes (bonus: 405)
This code is an anonymous function, that does the job, it will take a string, and return the required number.
```
@sum
```
[Answer]
# Go (59 characters)
```
func d(s string)(t int){for _,x:=range s{t+=int(x)};return}
```
Everything in Go is utf8 by default. Codetext in ` delimeters run through itself gives an output of: 5399.
[Answer]
# Javascript ES6, 41 bytes
```
_=>[..._].map(y=>x+=y.charCodeAt(),x=0)|x
```
*Thanks to @ETHproductions for 2 bytes saved!*
[Answer]
# SML, ~~42~~ 36
Just adding another language.
```
fun$x=foldl op+0(map ord(explode x))
```
Converts String to char array, calculates ascii number of each value and calculates the sum of all ascii numbers.
[Answer]
# [Gol><>](https://golfish.herokuapp.com/), 4 bytes
```
iEh+
```
[Answer]
# Jolf, 2 bytes
[Try it here!](http://conorobrien-foxx.github.io/Jolf/#code=dWk&input=SGVsbG8gV29ybGQh)
```
ui
u  sum of
 i  the input string
```
Umm... I don't know what else to say.
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 2 bytes
```
C∑
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCJD4oiRIiwiIiwiSGVsbG8gV29ybGQhIl0=)
### Explained
```
C∑
C  # char
 ∑ # sum
```
[Answer]
# C 32
```
f(char*s){return*s?*s+f(s+1):0;}
```
[Answer]
## D (function: 60)
Definitely not in it to win it.
Assuming it doesn't need to be a complete program
```
int c(string i){int s;foreach(e;i){s+=cast(int)e;}return s;}
```
Called like so
```
void main ()
{
    import std.stdio;
    auto hw = "Hello World!";
    writefln("%s = %d", hw, c(hw));
}
```
Output:
```
Hello World! = 1085
```
## D (program: 133)
Does not count line breaks.
```
void main(){import std.algorithm,std.stdio;stdin.byLine.map!((a){int s;foreach(e;a){s+=cast(int)e;}return s;}).reduce!"a+b".writeln;}
```
With more whitespace and longer variable names for readability
```
void main () {
    import std.algorithm, std.stdio;
    stdin.byLine
        .map!((line) {
                int sum;
                foreach (ch; line) {
                    sum += cast(int)ch;
                }
                return sum;
            })
        .reduce!"a+b"
        .writeln;
}
```
To support line breaks in the input, I could either use `byLine(KeepTerminator.yes)` — the correct way, for 20 characters — or append a `'\n'` to my line — which breaks single-line input and may give the wrong sum on Windows because of CRLF, for 18 characters.
[Answer]
## JavaScript (ES6) 54 58
```
alert([].reduce.call(prompt(),(v,c)=>v+c.charCodeAt(0),0))
```
 54 bytes thanks to **nderscore**:
```
alert([...prompt()].reduce((v,c)=>v+c.charCodeAt(),0))
```
[Answer]
# Delphi (87 83)
```
function x(s:string):int64;var c:char;begin x:=0;for c in s do x:=result+ord(c)end;
```
### Ungolfed
```
function x(s:string):int64;
var
  c:char;
begin
  x:=0;
  for c in s do
    x:=result+ord(c)
end;
```
Loops through `S` adding the `ord` value of the char to the result. where x==result
## Edits:
Saved 4 characters by switching to int64 and changing the adding to the sum.
[Answer]
# k (8 chars)
```
+/6h$0:0
```
Q translation
```
sum `int$read0 0
```
Bonus value:
```
k)+/6h$0:0
+/6h$0:0
438i
```
[Answer]
# J (7)
So close, yet so far... Oh well, I guess 7 is decent enough, since this answer also accepts empty strings. (I'm basing my usage of a variable as input on the phrase `from a file, stdin or whatever`)
```
+/a.i.b
```
## Explanation:
```
a.
┌┬┐├┼┤└┴┘│─ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~��������������������������������������������������������������������������������������������������������������������������������
```
`a.` contains all ASCII chars. 
```
   'people' i. 'pow'
0 2 6
```
`x i. y` is similar to python's `[x.index(i) for i in y]`.
```
   a. i. 'Hello World!'
72 101 108 108 111 32 87 111 114 108 100 33
```
Therefor, `a. i. y` converts `y` to an array of its ASCII values
```
   +/1 2 3 4 5 6
21
```
`+/` is like `sum`: `+/1 2 3 4 5 6` means `1+2+3+4+5+6`
```
   +/ a. i. 'Hello World!'
1085
```
The whole thing in action
For the bonus:
```
   b=:'+/a.i.b'
   +/a.i.b
482
```
Not bad, I guess.
```
   b=:'0\{+}/'
   +/a.i.b
478
```
Well, darn.
```
   A=:'+/a.i.A'
   +/a.i.A
449
```
Thanks @algorithmshark
```
    A=:'+/3 u:A'
    +/3 u:A
413
```
Thanks @marinus
[Answer]
## R, ~~35 characters (sum of 3086)~~ 26 bytes (sum of 2305)
```
sum(utf8ToInt(readline()))
```
`readline()` is one character longer than `scan(,"")` but `scan` split the input on spaces by default.
Usage:
```
> sum(utf8ToInt(readline()))
Hello World!
[1] 1085
> sum(utf8ToInt(readline()))
sum(utf8ToInt(readline()))
[1] 2305
> sum(utf8ToInt(readline()))
q/%8hnp>T%y?'wNb\},9krW &D9']K$n;l.3O+tE*$*._B^s!@k\&Cl:EO1zo8sVxEvBxCock_I+2o6 yeX*0Xq:tS^f)!!7=!tk9K<6#/E`ks(D'$z$\6Ac+MT&[s[]_Y(`<g%"w%cW'`c&q)D$0#C$QGf>?A$iawvc,}`9!('`c&q)D$0#C$QGf>?A$iawvc,}`9!(
[1] 14835
```
[Answer]
# Java 8, 113 chars
```
BigInteger C(String s){BigInteger i=BigInteger.ZERO;s.chars().forEach(x->i=i.add(BigInteger.valueOf());return i;}
```
*Note* each character in Java is Unicode 1-4 bytes unsigned integer, using `sum` function would easily overflow.
**Detailed**
```
BigInteger C (String s)
{
    BigInteger i = BigInteger.ZERO;
    s.chars().forEach(x -> i = i.add(BigInteger.valueOf(x));
    return i;
}
```
# Java 8, 57 chars
*ASCII only solution*
```
int C(String s){return s.chars().filter(x->x<128).sum();} 
```
**Detailed** [try here](http://ideone.com/FB1d8x)
```
public static int C (String s)
{
    return s
        .chars() // stream the characters
        .filter(x -> x < 128) // filter ASCII (optional)
        .sum(); // return the sum
}
```
]