# Convert a binary 'number' in string/or variable form to decimal in MSX-BASIC

I searched in my MSX books and googled for an answer, but I can find it. Maybe someone can help me...

In MSX-BASIC I am aware I can convert binary easily to decimal for example;
PRINT &B11111111
255
Ok

But what if I have this binairy 'number' comes in string form like A\$="11111111"?
Something like PRINT &B(A\$) does not work? I also tried to make a variable of it by using the VAL command. But I just can get it to work. So: convert a string/or variable to decimal. Any one idea's?

Next to that I am also looking for a way to make this binairy number (same form)
to convert it to the complementairy form, so input 10111010 with as result 01000101.

Aangemeld of registreer om reacties te plaatsen

Print val("&B111")

PRINTS 7

```10 a\$="00000101"
20 print ((&b11111111) xor val("&b" + a\$))

```
ray2day wrote:

Next to that I am also looking for a way to make this binairy number (same form)
to convert it to the complementairy form, so input 10111010 with as result 01000101.

INPUT A\$:FOR I=1 TO LEN(A\$):?CHR\$(ASC(MID\$(A\$,I))XOR 1);:NEXT

@st1mpy & @NYYRIKKI BIG THANKS!

```
10 a\$="00000101"
20 b=(NOT val("&b" + a\$))
30 print bin\$(b)
```

This prints 16 bits so still needs fixing

Why not simply:

```A\$="10111010":A=VAL("&B"+A\$):B\$=RIGHT
\$(BIN\$(NOTA),8):PRINT A\$+" in decimal
is"+STR\$(A)+", and its complement in
binary is ";B\$
10111010 in decimal is 186, and its c
omplement in binary is 01000101
Ok
```

Yes I discovered that too! Anyhow thanks for all your help!

Specific to @Manuel (do not understand why you didn’t ask... -smile-) I asked this question, because with some MSX computer Magazine articles and the MSX Redbook I am learning and teaching myself about the memory structure of MSX and MSX2. (Where possible) I do some MSX-BASIC memory reading tests, to check if my findings are correct...

ray2day wrote:

convert it to the complementairy form, so input 10111010 with as result 01000101.

Realtime version that works for any length
I=384+BASE(2+5*PEEK(&HFCAF)):FORI=ITO7+I:V=VPEEK(I+8):VPOKEI+8,VPEEK(I):VPOKEI,V:NEXT