Decimal > Binary Decimal < Binary
Decimal > Binary Decimal < Binary
(OP)
I need help making a function that converts decimal to binary and vice versa.
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS Contact USThanks. We have received your request and will respond promptly. Come Join Us!Are you a
Computer / IT professional? Join TekTips Forums!
*TekTips's functionality depends on members receiving email. By joining you are opting in to receive email. Posting Guidelines 

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.
Here's Why Members Love TekTips Forums:
Register now while it's still free!
Already a member? Close this window and log in.
RE: Decimal > Binary Decimal < Binary
Temp& = 0
Length% = LEN(Bit$)
FOR X% = 1 TO Length%
IF MID$(Bit$, Length%  X% + 1, 1) = "1" THEN
Temp& = Temp& + 2 ^ (X%  1)
END IF
NEXT X%
IF Temp& > 32767 THEN
Bin% = Temp&  65536
ELSE
Bin% = Temp&
END IF
END FUNCTION
FUNCTION BinDec& (Binary$) STATIC
Decimal& = 0
Power% = 0
Binary$ = UCASE$(Binary$)
FOR I% = LEN(Binary$) TO 1 STEP 1
Digit% = ASC(MID$(Binary$, I%, 1))  48
IF Digit% < 0 OR Digit% > 1 THEN
Decimal& = 0
EXIT FOR
END IF
Decimal& = Decimal& + Digit% * 2 ^ (Power%)
Power% = Power% + 1
NEXT I%
BinDec& = Decimal&
END FUNCTION
RE: Decimal > Binary Decimal < Binary
RE: Decimal > Binary Decimal < Binary
if
Bin%(101101) will come out to 45
RE: Decimal > Binary Decimal < Binary