[Question]
  [
You've just been hired by a German car manufacturing company. Your first task, as an engineer, is to write a program that computes the ecological footprint of ASCII strings.
The ecological footprint of character is computed as follows:
> 
> Write the character's ASCII code in binary, and count the number of 1's.
> 
> 
> 
For example, `A` has a footprint of 2, but `O` is dirtier with a footprint of 5.
> 
> The global footprint of a string is the sum of the footprints of its characters. An empty string has a footprint of zero.
> 
> 
> 
Your program must accept an ASCII string as parameter (through command line or input), compute its ecological footprint, and output it. The program itself must be ASCII encoded.
There is a hiccup though. As your company wishes to enter a new market with stricter environmental rules, you need to tune your program so that it behaves differently in "test mode". Thus:
> 
> The program should output 0 when it receives the string `test` as parameter.
> 
> 
> 
**Scoring**
The source code with the **smallest ecological footprint** wins (and yes, the answer `test` is forbidden!)
  
[Answer]
# CJam, ~~33~~ 31
```
"",AA#b:c~
```
There are 11300000000950000000034000000011600000001010000000115000000011600000000340000000061000000003300000000420000000058000000010500000000500000000102000000009800000000490000000102000000009800000000490000000098 null bytes between the double quotes.
The code is equivalent to
```
11300000000950000000034000000011600000001010000000115000000011600000000340000000061000000003300000000420000000058000000010500000000500000000102000000009800000000490000000102000000009800000000490000000098
AA#b:c~
```
which can be [tested online](http://cjam.aditsu.net/#code=11300000000950000000034000000011600000001010000000115000000011600000000340000000061000000003300000000420000000058000000010500000000500000000102000000009800000000490000000102000000009800000000490000000098%0AAA%23b%3Ac~&input=test).
### How this works
```
"",  e# Push the length of the string.
AA#  e# Push 10000000000.
b    e# Turn the length into the array of its base-10000000000 digits.
:c   e# Cast each digit to character. This pushes the following:
     e# q_"test"=!*:i2fb1fb1b
~    e# Evaluate the string.
```
### How that works
```
q_     e# Read all input and push a copy.
"test" e# Push the string "test".
=!*    e# Check for inequality and repeat the string 0 or 1 times.
       e# This replaces input "test" with the empty string.
:i     e# Cast each character to integer
2fb    e# Replace each integer by the array of its base-2 digits.
1fb    e# Replace each array of base-2 digits by the sum of its digits.
1b     e# Add the sums of digits.
```
This source code has an ecological footprint of 75.
[Answer]
# [Lenguage](http://esolangs.org/wiki/Lenguage), 0
```
```
Output is in [unary](http://meta.codegolf.stackexchange.com/q/5343), since Lenguage/Brainfuck has no sane way of printing integers in base 10.
The actual source code contains
```
22360559967824444567791709913713659826044558304969374451791514225490473373040212332757409553558758107085015797320276213515502796255082717802632399123502087743818475438512153373406931103005017157351410347278489842099128517039634739852783737052963203448945756470632484148121769939122103257063633371522287190530269279693540898545359211009781370158317748609540216376596783541124510013448091325488601732964773653391702083563797082990404753843419895799343996435988722965711513708742853668363743953430527328863418281733901770990932025503662188187254784985474815936854540100376410040743052620419372327997519047616042603909398552951490180076364164838561112002025592431155898041427468731461614504254168899805662501979953318388813759833797929243626668399650485310047043700001093878284174322463350892654886806075148010832042248607926124030339950499631072150856939786062937034833055717723216663269161130154002679878012158315587925933383341827053312086716181702533743607685576475754259877651521989944802973721727159955208722180232955193930065862370838526521351991966172723976565264862909528310162816593997640732796289501819499741414526385058421824690665542546821941125191276568479078107133076037506211133628962099403163812267452274532219562823184225236020523509355625620557197876838014050964240952738109101849512504021041103516630358995290177306585560988278630098667702211916671663291473843258785929522017507744814910480115446168939335008597569919072874897148594826036210511162928991890818427747059833051607455121463371211282760364668765311589329918870071117807132901910082663054895226456039171170783440772764031568108965851688162729239711772886386306884508520204834432674839183166053019421652064937613583258148354531835035461504442885024563141848164279928769795684221364984104923764359842286827870778678989243517189772102669283996930513577004801536579491093711362942690905779844535371088542020595945700544234301668098553671685123172583259206072965508639556627967633275762621813851479909708616154198658896714629908456913467267354690109885368211752176196164620615081464122410029328694509842558492529684841818953632659248840216891072110853731776562597900145806210691868173380612838327841104919352821441230296200143603175486627682007399030356592930049570084097858148122367
```
null bytes and is equivalent to the following Brainfuck program:
```
,[<<+++++++++++++++++++++++++++++++++++++++++++++++++>>>>>>,]
>>>>>>>>>>>>>>>>>>>>>>>>+<<<<<<<<<<<<<<<<<<<<<<<<
<<<++++++++++++++++++++++++++++
[-<----<<<<----<<<<----<<<<---->>>>>>>>>>>>>]
<----<<<<---<<<<+++++++++++<<<<----
<<<<
[>>>>>>>>>>>>>>>>>>>>>>>>]
>>>>
[>>>>>>>>>>>>>>>>>>>>>>>>]
>>>>
[>>>>>>>>>>>>>>>>>>>>>>>>]
>>>>
[>>>>>>>>>>>>>>>>>>>>>>>>]
>>>>
[>>>>>>>>>>>>>>>>>>>>>>>>]
>>>>
[
 <<<<<<<<<<<<<<<<<<<<<<<<
 <<<++++++++++++++++++++++++++++
 [-<++++<<<<++++<<<<++++<<<<++++>>>>>>>>>>>>>]
 <++++<<<<+++<<<<-----------<<<<++++
 >>>>>>>>>>>>
 [
  -[<]<<[.<]
  >>>
  -[<]<<[.<]
  >>>
  -[<]<<[..<]
  >>>
  -[<]<<[.<]
  >>>
  -[<]<<[..<]
  >>>
  -[<]<<[..<]
  >>>
  -[<]<<[...<]
  >>>
  -[<]<<[.<]
  >>>
  -[<]<<[..<]
  >>>
  -[<]<<[..<]
  >>>
  -[<]<<[...<]
  >>>
  -[<]<<[..<]
  >>>
  -[<]<<[...<]
  >>>
  -[<]<<[...<]
  >>>
  -[<]<<[....<]
  >>>
  -[<]<<[.<]
  >>>
  -[<]<<[..<]
  >>>
  -[<]<<[..<]
  >>>
  -[<]<<[...<]
  >>>
  -[<]<<[..<]
  >>>
  -[<]<<[...<]
  >>>
  -[<]<<[...<]
  >>>
  -[<]<<[....<]
  >>>
  -[<]<<[..<]
  >>>
  -[<]<<[...<]
  >>>
  -[<]<<[...<]
  >>>
  -[<]<<[....<]
  >>>
  -[<]<<[...<]
  >>>
  -[<]<<[....<]
  >>>
  -[<]<<[....<]
  >>>
  -[<]<<[.....<]
  >>>
  -[<]<<[.<]
  >>>
  -[<]<<[..<]
  >>>
  -[<]<<[..<]
  >>>
  -[<]<<[...<]
  >>>
  -[<]<<[..<]
  >>>
  -[<]<<[...<]
  >>>
  -[<]<<[...<]
  >>>
  -[<]<<[....<]
  >>>
  -[<]<<[..<]
  >>>
  -[<]<<[...<]
  >>>
  -[<]<<[...<]
  >>>
  -[<]<<[....<]
  >>>
  -[<]<<[...<]
  >>>
  -[<]<<[....<]
  >>>
  -[<]<<[....<]
  >>>
  -[<]<<[.....<]
  >>>
  -[<]<<[..<]
  >>>
  -[<]<<[...<]
  >>>
  -[<]<<[...<]
  >>>
  -[<]<<[....<]
  >>>
  -[<]<<[...<]
  >>>
  -[<]<<[....<]
  >>>
  -[<]<<[....<]
  >>>
  -[<]<<[.....<]
  >>>
  -[<]<<[...<]
  >>>
  -[<]<<[....<]
  >>>
  -[<]<<[....<]
  >>>
  -[<]<<[.....<]
  >>>
  -[<]<<[....<]
  >>>
  -[<]<<[.....<]
  >>>
  -[<]<<[.....<]
  >>>
  -[<]<<[......<]
  >>>
  -[<]<<[.<]
  >>>
  -[<]<<[..<]
  >>>
  -[<]<<[..<]
  >>>
  -[<]<<[...<]
  >>>
  -[<]<<[..<]
  >>>
  -[<]<<[...<]
  >>>
  -[<]<<[...<]
  >>>
  -[<]<<[....<]
  >>>
  -[<]<<[..<]
  >>>
  -[<]<<[...<]
  >>>
  -[<]<<[...<]
  >>>
  -[<]<<[....<]
  >>>
  -[<]<<[...<]
  >>>
  -[<]<<[....<]
  >>>
  -[<]<<[....<]
  >>>
  -[<]<<[.....<]
  >>>
  -[<]<<[..<]
  >>>
  -[<]<<[...<]
  >>>
  -[<]<<[...<]
  >>>
  -[<]<<[....<]
  >>>
  -[<]<<[...<]
  >>>
  -[<]<<[....<]
  >>>
  -[<]<<[....<]
  >>>
  -[<]<<[.....<]
  >>>
  -[<]<<[...<]
  >>>
  -[<]<<[....<]
  >>>
  -[<]<<[....<]
  >>>
  -[<]<<[.....<]
  >>>
  -[<]<<[....<]
  >>>
  -[<]<<[.....<]
  >>>
  -[<]<<[.....<]
  >>>
  -[<]<<[......<]
  >>>
  -[<]<<[..<]
  >>>
  -[<]<<[...<]
  >>>
  -[<]<<[...<]
  >>>
  -[<]<<[....<]
  >>>
  -[<]<<[...<]
  >>>
  -[<]<<[....<]
  >>>
  -[<]<<[....<]
  >>>
  -[<]<<[.....<]
  >>>
  -[<]<<[...<]
  >>>
  -[<]<<[....<]
  >>>
  -[<]<<[....<]
  >>>
  -[<]<<[.....<]
  >>>
  -[<]<<[....<]
  >>>
  -[<]<<[.....<]
  >>>
  -[<]<<[.....<]
  >>>
  -[<]<<[......<]
  >>>
  -[<]<<[...<]
  >>>
  -[<]<<[....<]
  >>>
  -[<]<<[....<]
  >>>
  -[<]<<[.....<]
  >>>
  -[<]<<[....<]
  >>>
  -[<]<<[.....<]
  >>>
  -[<]<<[.....<]
  >>>
  -[<]<<[......<]
  >>>
  -[<]<<[....<]
  >>>
  -[<]<<[.....<]
  >>>
  -[<]<<[.....<]
  >>>
  -[<]<<[......<]
  >>>
  -[<]<<[.....<]
  >>>
  -[<]<<[......<]
  >>>
  -[<]<<[......<]
  >>>
  -[<]<<[.......<]
  <
 ]
]
```
Try it online on [brainfuck.tk](http://brainfuck.tk).
The length of the Brainfuck code is highly suboptimal – for starters, I've hardcoded the footprints of all ASCII characters – but score 0 is score 0...
[Answer]
# PowerShell, ~~337~~ ~~344~~ 304 points
```
PARAM([CHAR[]]$A)$A|%{$B+=([CONVERT]::TOSTRING(+$_,2)-REPLACE0).LENGTH};($B,0)[-JOIN$A-CEQ"test"]
```
I'M SHOUTING AT YOU BECAUSE IT'S CHEAPER!
Takes input as `$A`, then casts as a char-array, then iterates over a for-loop on each character, uses the ridiculously wordy `[convert]::ToString()` to convert the character at that position to binary, replaces all the 0's with nothing, then counts the length, and adds that to `$B`. At the end, uses an equivalence to index into a dynamic array (i.e., if `$A` is `test`, then `-CEQ` is `$TRUE`, so it indexes to the second element, `0`).
Edit1 -- Corrected test case `"TEST"`  
Edit2 -- Golfed a couple points by iterating over the characters themselves rather than their indices, and by remembering that `-replace` doesn't need a second parameter if you're replacing it with nothing.
[Answer]
# Pyth - ~~52~~ 49
*Three points save thanks to @orlp.*
```
*/.BQ`1nQ"test
```
Takes input in quotes to save footprint.
[Test Suite](http://pyth.herokuapp.com/?code=%2a%2F.BQ%601nQ%22test&test_suite=1&test_suite_input=%22A%22%0A%22o%22%0A%22hello%22%0A%22test%22%0A%22%2a%2F.BQ%601nQ%5C%22test%22&debug=0).
[Answer]
# Common Lisp, ~~294~~ ~~281~~ 235
*In order to reduce the score, I used `@` (cost 1) and `!` (cost 2) as variable names (edit: and it is even better if I use `@` for the variable occuring the most in the function).*
*I AM SHOUTING [TOO](https://codegolf.stackexchange.com/a/58716/903) because it is cheaper.*
```
(LAMBDA(@)(IF(STRING="test"@)0(LOOP FOR ! ACROSS @ SUM(LOGCOUNT(CHAR-CODE !)))))
```
### Pretty-printed
```
(LAMBDA (@)
  (IF (STRING= "test" @) 0
      (LOOP FOR ! ACROSS @ SUM (LOGCOUNT (CHAR-CODE !)))))
```
[Answer]
# JavaScript, 279
**Edit** Bug fix (did not count bit 1 of each char)
A complete program, with input and output via popup. Tested in Firefox, should work in any modern browser.
```
B=(P=prompt)(H=D=0)
while(B!="test"&&(A=B.charCodeAt(H++)))while(A)D+=A&1,A>>=1
P(D)
```
**Some tools** (Tested with Firefox)
```
w=c=>c.toString(2).split('').reduce(function(a,b){return a- -b})
t=[[],[],[],[],[],[],[],[],[]]
u=[[],[],[],[],[],[],[],[],[]]
for(c=1;c<256;c++)
  c<33|c>126&c<161 ? t[w(c)].push('\\'+c) : u[w(c)].push('&#'+c+';')
for(i=0; i++<8;)       
  T.innerHTML+=i+': '+u[i].concat(t[i]).join(' ')+'\n'
function Calc()
{
  var r='', t=0, b
  I.value.split('').forEach(function(c) {
    c = c.charCodeAt(), r += '\n&#'+c+' '+((256+c).toString(2).slice(1))+' : '
    for(b=0;c;c>>=1) b += c&1
    r += b, t += b
  })
  R.innerHTML='Total '+t+'\nDetail'+r
}
```
```
#I { width: 400px }
```
```
<b>Weight table</b><pre id=T></pre><br>
<b>Counter</b><br><textarea id=I></textarea><button onclick="Calc()">-></button> <pre id=R></pre>
```
[Answer]
# Julia, ~~254~~ ~~246~~ 232
```
P=readline()
print(P=="test"?0:sum([count_ones(1*A)for A=P]))
```
The `count_ones` function counts the number of ones in the binary representation of its input.
Reduced my ecological footprint thanks to FryAmTheEggman!
[Answer]
# Python 3, 271
```
z=input();print([sum([bin(ord(i)).count("1")for i in z]),0][z=="test"])
```
[Answer]
# Perl, ~~136~~ ~~118~~ 73
```
$_=unpack"B*";$_=y@1@@
```
Replace all `@` with `\0`
Usage example:
```
perl -p entry.pl entry.pl
```
[Answer]
# MATLAB, ~~198~~ 194 bytes
```
A=input('','s');~strcmp('test',A)*nnz(dec2bin(A)-48)
```
First, the string is read in from STDIN via the [`input`](http://www.mathworks.com/help/matlab/ref/input.html) function. Once this happens, we compare the input string to the string `test`. If the result **isn't** `test`, we convert each character to its ASCII code and then its binary representation via [`dec2bin`](http://www.mathworks.com/help/matlab/ref/dec2bin.html). A beautiful consequence of this function is that if you submit a string, the binary representation of its ASCII code is delimited as one character per line.
As an example:
```
>> dec2bin('ABCD')
ans =
1000001
1000010
1000011
1000100
```
`dec2bin` outputs a character array. Once this happens, subtract by 48, which is the ASCII code for 0 so that the matrix gets converted to `double` consisting of 0s and 1s. Once that happens, a call to [`nnz`](http://www.mathworks.com/help/matlab/ref/nnz.html) counts up the total number of non-zero elements in this matrix. Take note that this result is multiplied by the opposite of the string compare with `test`. Should the string **not** be `test`, we get the footprint calculation. If it's equal, then the multiplication results in 0.
Some examples:
```
>> A=input('','s');~strcmp('test',A)*nnz(dec2bin(A)-48)
A
ans =
     2
>> A=input('','s');~strcmp('test',A)*nnz(dec2bin(A)-48)
O
ans =
     5
>> A=input('','s');~strcmp('test',A)*nnz(dec2bin(A)-48)
test
ans =
     0
>> A=input('','s');~strcmp('test',A)*nnz(dec2bin(A)-48)
  %// Note - no characters were added here.  Simply pushed Enter
ans =
     0
```
[Answer]
# Bash ~~440~~ ~~430~~ ~~412~~ ~~405~~ 403
```
A=0
[ test != "$1" ]&&for((D=0;D<${#1};D++)){
A=$((A+`bc<<<$(printf "obase=2;%d" "'${1:$D:1}")|tr -d "0
"|wc -m`))
}
echo $A
```
Pretty straightforward. Loops characters in the input converting first to ascii (with `printf %d` and the leading `'` on the number then to binary (with `bc`), strips out the zeros and counts the number of characters.
Not a great answer but hadn't seen a bash attempt yet.
Modified since my first answer allowed the input string to be given simply on the command line (i.e. it became multiple input params if multipe words) but after reading some other answers I think I can assume it is quoted, so the whole string comes as `$1`
[Answer]
# Ceylon, ~~1431~~, ~~764~~, ~~697~~, ~~571~~, ~~547~~, ~~538~~, ~~501~~, ~~493~~, ~~467~~, 451
```
shared void p(){print(sum{0,if(exists a=process.arguments[0])if(a!="test")for(c in a)for(b in 0..7)if(c.hash.get(b))1});}
```
This was the original, ungolfed:
```
Integer footprintCharacter(Integer b) {
    return sum({0, for(i in 0..7) if(b.get(i)) 1 });
}
Integer footPrintString(String s) {
    if(s == "test") {return 0;}
    return sum({0, for(c in s) footprintCharacter(c.integer)});
}
shared void footprint() {
     if(exists s = process.arguments[0]) {
         print(footPrintString(s));
     } else {
         print("This program needs at least one parameter!");
     }
}
```
This takes the argument from a command line parameter ... process.arguments is an (possibly empty) sequence of strings, so before using one of them, we need to check if it actually exists. In the other case we output an error message (this is not required by the question and will be thrown away in the next versions).
Ceylon's [`sum`](https://modules.ceylon-lang.org/repo/1/ceylon/language/1.1.0/module-doc/api/index.html#sum) function takes a *non-empty* Iterable of elements of some type which needs to satisfy [`Summable`](https://modules.ceylon-lang.org/repo/1/ceylon/language/1.1.0/module-doc/api/Summable.type.html), i.e. has a `plus` method, like Integer. (It doesn't work with empty sequences because each Summable type will have its own zero, and the runtime has no chance to know which one is meant.)
The elements of a string, or the one bits of an integer, are not a non-empty iterable. Therefore we are using here the feature to build an iterable by specifying some elements, then a "comprehension" (which will get evaluated to zero or more elements). So in the character case we are adding ones (but only when the corresponding bit is set), in the string case we are adding the result of the characters. (The comprehension will only be evaluated when the receiving function actually iterates over it, not when building the Iterable.)
Let's see how we can shrink this down. First, each of the functions is only called at one place, so we can inline them. Also, as mentioned above, get rid of the error message. (764 footprint points.)
```
shared void footprint() {
    if (exists s = process.arguments[0]) {
        if (s == "test") {
            print(0);
        } else {
            print(sum({ 0, for (c in s) sum({ 0, for (i in 0..7) if (c.integer.get(i)) 1 }) }));
        }
    }
}
```
We don't actually need the inner nested `sum`, we can make this one big comprehension. (This saves us 37 footprint points for `sum({0,})`, and some more for whitespace, which will be eliminated at the end anyways.) This is 697:
```
shared void footprint() {
    if (exists s = process.arguments[0]) {
        if (s == "test") {
            print(0);
        } else {
            print(sum({ 0, for (c in s) for (i in 0..7) if (c.integer.get(i)) 1 }));
        }
    }
}
```
We can apply a similar principle to the special cased `"test"` string: as in that case the result is 0 (i.e. nothing is contributed to the sum), we can just do this as a part of the summation (but we have to invert the condition). This mainly saves us the `print(0);`, some braces and a bunch of indentation spaces, coming down to a footprint of 571:
```
shared void footprint() {
    if (exists s = process.arguments[0]) {
        print(sum({ 0, if (s != "test") for (c in s) for (i in 0..7) if (c.integer.get(i)) 1 }));
    }
}
```
We do the same for the first `if`, with the side effect that now giving no argument also outputs `0` instead of doing nothing. (At least I thought that would happen here, instead it seems to hang with an eternal loop? Strange.)
```
shared void footprint() {
    print(sum({ 0, if (exists s = process.arguments[0]) if (s != "test") for (c in s) for (i in 0..7) if (c.integer.get(i)) 1 }));
}
```
We can actually omit the `()` for the `sum` function here, using an [alternative function call syntax](http://ceylon-lang.org/documentation/1.1/reference/operator/invoke/), which uses `{...}` instead of `()`, and will fill in comprehensions into iterable arguments. This has footprint 538:
```
shared void footprint() {
    print(sum{ 0, if (exists s = process.arguments[0]) if (s != "test") for (c in s) for (i in 0..7) if (c.integer.get(i)) 1 });
}
```
Replacing the function name `footprint` (40) by `p` (3) saves another 37 points, bringing us to 501. (Ceylon function names have to start with lower case characters, so we can't get less than 3 points here.)
```
shared void p() {
    print(sum{ 0, if (exists s = process.arguments[0]) if (s != "test") for (c in s) for (i in 0..7) if (c.integer.get(i)) 1 });
}
```
The variable names `s` (5) and `c` (4), `i` (4) are also not optimal. Let's replace them by `a` (argument), `d` (digit?) and `b` (bit-index). Footprint 493:
```
shared void p() {
    print(sum{ 0, if (exists a = process.arguments[0]) if (a != "test") for (c in a) for (b in 0..7) if (c.integer.get(b)) 1 });
}
```
I don't see any remaining non-whitespace optimization, so let's remove the non-needed whitespace (1 point for each space, two for each of the two line breaks):
```
shared void p(){print(sum{0,if(exists a=process.arguments[0])if(a!="test")for(c in a)for(b in 0..7)if(c.integer.get(b))1});}
```
When browsing the API, I found that [Character.hash](https://modules.ceylon-lang.org/repo/1/ceylon/language/1.1.0/module-doc/api/Character.type.html#hash) actually returns the same value as its `integer` attribute. But it has just 14 points instead of 30, so we come down to 451!
```
shared void p(){print(sum{0,if(exists a=process.arguments[0])if(a!="test")for(c in a)for(b in 0..7)if(c.hash.get(b))1});}
```
[Answer]
# PowerShell, 273 336 328 324 293 288 295
```
PARAM($A)[CHAR[]]$A|%{$D=[INT]$_;WHILE($D){$B+=$D-BAND0X1;$D=$D-SHR1}};($B,0)[$A-CEQ"test"]
```
edit - forgot the 'test' case ... so much expensive.
editedit - missed an UPPERCASE opportunity.
editeditedit - incorporated the comment suggestions (Thanks TimmyD).
edit 4 - D is a cheaper varable than C (2 vs. 3)
edit 5 - Back to 295 due to the case-sensitivity check.
Loops over the string and counts the 1s which get shifted off the characters ASCII value.
Hat-tip to TimmyD for giving me the foresight to use uppercase characters AND to use the array index at the end.
[Answer]
# Matlab, 320
```
A=(input('','s'));nnz(floor(rem(bsxfun(@times,[A 0],2.^(-7:0)'),2)))*~strcmp(A,'test')
```
[Answer]
# C,374
Newlines (not included in score) added for clarity. Could be improved to 360 just by changing variable names to uppercase, but I'll try to think of something better.
Input is via commandline, which means it segfaults on absent input. I expect a worse score for input through stdin.
```
i,t;
main(int c,char**v){
for(;c=v[i][i/8];i++)t+=(c>>i%8)&1;
printf("%d",strcmp(v[1],"test")?t:0);
}
```
[Answer]
# PHP, ~~377~~ ~~337~~ 299 Ecological Footprint ***(still a lot)***, ~~102~~ 91 Bytes
Seems that PHP is environment friendly in test-mode only. ;)
```
WHILE($D<STRLEN($A=$argv[1]))$B+=SUBSTR_COUNT(DECBIN(ORD($A[$D++])),1);ECHO"test"!=$A?$B:0;
```
Runs from command line like:
```
php footprint.php hello
php footprint.php test
```
`while` is more environment friendly than `for` even though they share the same character count. Also uppercase variable names have a better footprint than their lowercase counterparts.
**Edit**
* saved 40 points by using uppercase function names.
* saved 38 points by using [`decbin`](http://php.net/manual/de/function.decbin.php) instead of [`base_convert`](http://php.net/manual/de/function.base-convert.php)
[Answer]
**VBA, ~~475~~ 418**
*Thanks Jacob for 57 points off*
* Converts String to Byte Array (128 is vba shortcut for "Converts the string from Unicode to the default code page of the system" So won't work on Mac....)
* Loops though byte array converting to Binary and Concatenating everything together.
* checks for test
* Prints length of string with all the 0's replaced with nothing
VBA why are you so bad at golfing... :(
```
SUB A(D)
DIM B() AS BYTE
B=STRCONV(D,128)
FOR P=0 TO UBOUND(B)
H=H+APPLICATION.DEC2BIN(B(P))
NEXT
IF D="test" THEN H=0
MSGBOX LEN(REPLACE(H,0,""))
ENDSUB
```
[Answer]
# JavaScript, 418 410
```
A=prompt();B=0;!A||A=="test"?0:A.split("").forEach(D=>B+=D.charCodeAt().toString(2).match(/1/g).length);alert(B)
```
[Answer]
# Pyth, 64
```
?qz"test"0l`sS.Bz
```
Checks if the input is test and if not, counts the number of 1's in the binary representation of the input.
[Answer]
# Haskell, 292
```
a 0=0
a b=rem b 2+a(div b 2)
b"test"=0
b d=sum$map(a.fromEnum)d
main=interact$show.b
```
Nothing much to say here: turn every character into ascii value (`fromEnum`) and calculate the `1`s (via `a`). Sum all the results.
[Answer]
# JavaScript (ES6), ~~521~~ ~~478~~ ~~458~~ ~~449~~ ~~473~~ 465
```
alert(((A=prompt(),A!="test")&&(A!=""))?(A.split``.map(H=>(H.charCodeAt().toString(2).match(/1/g)||[]).length)).reduce((A,B)=>A+B):0)
```
This is my first attempt at a JavaScript golf, so it's probably very ungolfed.
[Answer]
# Ruby, ~~316~~ 313
Very straightforward, looking for some more golfing possibilities:
```
b=gets.chomp;b=='test'?0:b.chars.map{|i|i.ord.to_s(2).count('1')}.inject(:+)
```
* Used `b` instead of `x` to save 3 points.
[Answer]
# Python 2, ~~294~~ ~~281~~ ~~269~~ 266
```
A=input()
print sum(format(ord(H),"b").count("1")for H in A)if A!="test"else 0
```
A port of my Pyth answer, above.
Input is received as a string (with quotes):
```
"ABC"
```
[Answer]
# CJam, 123
```
q_"test"={;0}{{s2b2b~}%1e=}?
```
[Answer]
# Pyth, 96
```
Iqz"test"0.q)/j""m.BdmCdz\1
```
A port of my CJam answer, above/below.
[Answer]
# CJam, ~~83~~ ~~81~~ ~~79~~ 77
Best so far after trying a number of variations:
```
l0$"test"=!\:i2fbe_1b*
```
[Try it online](http://cjam.aditsu.net/#code=l0%24%22test%22%3D!%5C%3Ai2fbe_1b*&input=l0%24%22test%22%3D!%5C%3Ai2fbe_1b*)
Explanation:
```
l       Get input. Other options like q and r are the same number of bits.
0$      Copy input for comparison. This saves 2 bits over _.
"test"  Push special case string.
=       Compare.
!       Negate so that we have 0 for special case, 1 for normal case.
\       Swap input string to top.
:i      Convert characters to integers.
2fb     Apply conversion to base 2 to all values.
e_      Flatten array.
1b      Sum up the bits. This is 2 bits shorter than :+.
*       Multiply with result from special case test.
```
[Answer]
# Ruby, 247
Straightforward approach looping through all bytes of the input and all bits in each byte, summing to variable `d`.
`d` is initialized to -2 because `h` contains the terminating newline from the input (worth 2 bits) and we do not want to count that.
Similarly `h` will contain `test` with a trailing newline, so a newline must included in the comparison value.
```
d=-2
h=gets
h.bytes{|a|8.times{|b|d+=a>>b&1}}
p h=='test
'?0:d
```
[Answer]
# R, 279
```
sum(as.integer(rawToBits(charToRaw(if((s=readline())=='test')''else s))))
```
Pretty self explanatory.  
Tests:
```
> sum(as.integer(rawToBits(charToRaw(if((s=readline())=='test')''else s))))
sum(as.integer(rawToBits(charToRaw(if((s=readline())=='test')''else s))))
[1] 279
> sum(as.integer(rawToBits(charToRaw(if((s=readline())=='test')''else s))))
A
[1] 2
> sum(as.integer(rawToBits(charToRaw(if((s=readline())=='test')''else s))))
O
[1] 5
> sum(as.integer(rawToBits(charToRaw(if((s=readline())=='test')''else s))))
test
[1] 0
> sum(as.integer(rawToBits(charToRaw(if((s=readline())=='test')''else s))))
OAO
[1] 12
```
[Answer]
## C, 378 footprint, 98 bytes
Another C solution:
```
s;main(c,a)char**a;{for(s=-17*!strcmp(a[1],"test");c=*a[1]++;)for(;c;s+=c&1,c/=2);printf("%d",s);}
```
The way this works is that s is initialized to 0 usually, but becomes -17 if the command-line argument is "test" (strcmp returns 0 on equal strings, and non-zero on distinct strings, so inverting it gives 1 if string is "test"). The number -17 was chosen to compensate for the footprint of 17 that will be calculated for "test". The computation of the footprint is easy with bitwise operators.
Snap! I initially missed the "shortest footprint wins" so I was aiming for shortest code... I'll see if I can make the "footprint" smaller.
[Answer]
# Java, 594
```
class A{public static void main(String[]P){Integer D,H;for(D=H=0;D<P[0].length();)H+=D.bitCount(P[0].charAt(D++));System.out.print(P[0].equals("test")?0:H);}}
```
Java is not very green.
Ungolfed version:
```
class A {
    public static void main(String[]P) {
        Integer D,H;
        for(D=H=0;D<P[0].length();)
            H+=D.bitCount(P[0].charAt(D++));
        System.out.print(P[0].equals("test")?0:H);
    }
}
```
`D` is declared as an `Integer` so we can access `Integer`'s static `bitCount` method in an environmentally conscientious manner. The `bitCount` method treats the `char`s as integers and returns the number of set bits.
]