Decimal To Binary

Routine Summary

Converts a decimal (base 10) number to a binary (base 2) number.

Inputs

A - The decimal number that you want to convert.

Outputs

L₁ - The binary representation of the decimal number, expressed as a list.

Variables Used

A, B, L₁

Calculator Compatibility

TI-83/84/+/SE

Author

imcoraline

dtb.zip

``````:1+int(log(A)/log(2→dim(L₁
:For(B,Ans,1,-1
:2fPart(A/2→L₁(B
:int(A/2→A
:End```
```

This routine takes a positive whole decimal number (base 10), stored in A, and converts it to the equivalent binary (base 10) representation. The binary representation will be in list form. For example, the decimal number 32 is the binary number 100000, meaning the routine would result in the list {1,0,0,0,0,0}. To learn how to convert a decimal number to a binary number, vice versa, and even see how to convert to and from other bases besides decimal and binary, see the Binary and Hexadecimal page.

It also may be important to note that adding 0’s to the front of a binary number will not change the decimal equivalent. For example, both 01101012 and 1101012 are equivalent to 5310.

# Error Conditions

• ERR:DATATYPE is thrown if A is imaginary.
• ERR:NONREALANS is thrown if A is negative.
• ERR:DOMAIN is thrown if A is 0.
• An error will not be thrown is A isn’t an integer. Nonetheless, the conversion will not work correctly.

.