# How to replace the value that include infinity?

Good day,

I have the output A and I want to do some operation to A:

A = {0, 1, 2}
B = -Total[(#*Log2[#]& /@ A]


when i run, has error :

Indeterminate expression 0 (-\[Infinity]) encountered. >>


How can I edit the coding, if I want to use

If output A=0, the value of #*Log2[#]=0


Thank you very much

Do a check:

If[# == 0, 0, # Log2[#]] & /@ A


Or, you don't have to know the limiting value(s) beforehand:

Limit[x Log2[x], x -> #] & /@ A


### Update: holding evaluation

hold = Hold[# Log2[#]] & /@ A


{Hold[0 Log2[0]], Hold[1 Log2[1]], Hold[2 Log2[2]]}

ReleaseHold[hold /. HoldPattern[0 Log2[0]] -> 0]


{0, 0, 2}

• I want to substitute the value of 0Log2(0) as 0. Thank you, I do it first. Commented Aug 4, 2016 at 5:59
• @munirah In that case you shouldn't let Log2[0] evaluate.
– BoLe
Commented Aug 4, 2016 at 6:05
• @munirah, that's what the If[] is for; an alternative would be to use Piecewise[]. Commented Aug 4, 2016 at 6:08
• @munirah Version 10 features inactivated expressions which might be interesting to you.
– BoLe
Commented Aug 4, 2016 at 6:20
• thank you for helping me, I understand it now Commented Aug 4, 2016 at 6:20