See also: hexToDec, octToDec

Converts a binary number string to a decimal number.

Syntax

JSV_binToDec(expB)

Prototype

expB.binToDec()

Returns

The binToDec function returns the decimal number of the binary number string.

Parameters

The binToDec function uses the following arguments.

Argument Description
expB The binary number string that is to be converted to a decimal.

Remarks

There is no checking whether expB is a binary string. Users of this function should check that the value of expB is a valid argument to this function.

Uses the parseInt function to return an integer representing the specified binary string. If the first character cannot be converted to a number, parseInt returns NaN.

Dependencies

n/a

Example

The following lines of code

var f = "101011";
document.write( "The number " + f + " is decimal " + JSV_binToDec(f) );
f = "1011110110";
document.write( "The number " + f + " is decimal " + JSV_binToDec(f) );

produce