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

Door ray2day

Hero (657)

afbeelding van ray2day

25-02-2021, 18:54

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.

Thanks in advance for your help!

Aangemeld of registreer om reacties te plaatsen

Van st1mpy

Paladin (757)

afbeelding van st1mpy

25-02-2021, 19:33

Print val("&B111")

PRINTS 7

Van st1mpy

Paladin (757)

afbeelding van st1mpy

25-02-2021, 19:52

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


Van NYYRIKKI

Enlighted (5745)

afbeelding van NYYRIKKI

25-02-2021, 20:00

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

Van ray2day

Hero (657)

afbeelding van ray2day

25-02-2021, 20:26

@st1mpy & @NYYRIKKI BIG THANKS! Smile

Van st1mpy

Paladin (757)

afbeelding van st1mpy

25-02-2021, 20:32


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

This prints 16 bits so still needs fixing

Van Manuel

Ascended (17877)

afbeelding van Manuel

25-02-2021, 21:12

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

Van ray2day

Hero (657)

afbeelding van ray2day

25-02-2021, 21:44

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...

Van NYYRIKKI

Enlighted (5745)

afbeelding van NYYRIKKI

25-02-2021, 22:17

ray2day wrote:

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

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