v3n0mn33dl3
Moldy Popcorn
public text 4 hire!
Posts: 33
|
Post by v3n0mn33dl3 on Nov 18, 2016 16:44:40 GMT -5
Hi All,
it's been pretty a long time and I notice the forum is pretty quiet but if I dont shoot I'll certainly miss....
the 61 in the following example is a variable
a$ = "&h" b$ = "61" c$ = a$+b$ print chr$(c$)
I did expect to get "a" but instead I get an error
how can I make this work?
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Nov 18, 2016 18:24:04 GMT -5
Requires an integer value, not a string.
|
|
|
Post by mekanaizer on Nov 18, 2016 20:36:39 GMT -5
In BASIC I can only recall something like this:
a = 36 b = 61 c = a + b print chr$(c)
OR
print chr$(&h61)
|
|
v3n0mn33dl3
Moldy Popcorn
public text 4 hire!
Posts: 33
|
Post by v3n0mn33dl3 on Nov 19, 2016 3:42:25 GMT -5
thanks guys!
so the solution is to use "36" instead of "&h"
*edit*
but this gives me a problem when trying to make "&h6J" that would make an "o"
so still stuck with this error.
*edit 2*
I also tried to use the octal system, which would make things a lot easier but basiegaxorz does not support "OCT$" or "&o"
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Nov 19, 2016 9:33:02 GMT -5
Octal isn't common in programming.
Use hex without quotes, and also remember hex's boundaries (0 to F, not J.
Print chr$(67) Print chr$(&h43)
|
|
v3n0mn33dl3
Moldy Popcorn
public text 4 hire!
Posts: 33
|
Post by v3n0mn33dl3 on Nov 19, 2016 10:41:25 GMT -5
Octal isn't common in programming. Use hex without quotes, and also remember hex's boundaries (0 to F, not J. Print chr$(67) Print chr$(&h43) Yes I know, but my last correction changing J to F wasnt saved... the forum kant really working on my phone.... My probleem is that the hex code is input with the controller in two parts. So part 1 world be "6" and part 2 would be "F" when I put the two together chr$ wont work.
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Nov 19, 2016 11:33:55 GMT -5
Ah, yeah, I have some issues on some forums with my phone as well, so I feel your pain If you need to split up the value into 2 parts, you can do: a = &h0 b = &h43 print chr$(a + b)
Or you could do: c = a + b and just pass "c" to the chr$() function. Hope that helps!
|
|
v3n0mn33dl3
Moldy Popcorn
public text 4 hire!
Posts: 33
|
Post by v3n0mn33dl3 on Nov 19, 2016 13:21:49 GMT -5
Ah, yeah, I have some issues on some forums with my phone as well, so I feel your pain If you need to split up the value into 2 parts, you can do: a = &h0 b = &h43 print chr$(a + b)
Or you could do: c = a + b and just pass "c" to the chr$() function. Hope that helps! Yes that helps, thanks again. .... good to know about the quotes but.... the HEX code is constructed from two parts. so to get "6F" to print an "o" the user inputs binary (0110) for 6 and binary (1111) for F the only way I know how to put these together to get "6F" is as a string, and the string is not compatible with chr$
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Nov 19, 2016 13:48:17 GMT -5
You'll have to write a function to convert binary to hex, or even easier, to integer.
Something like this should get you started:
pos = 0 for n = len(str$) to 1 step -1 b$ = mid$(str$,n,1) if b$ = "1" then ' total+=2^n ' This works in SecondBASIC and would eliminate the code below if pos = 0 then total = 1 else temp_val = 1 for i = 1 to pos temp_val = temp_val * 2 next total+=temp_val end if end if pos++ next
|
|
v3n0mn33dl3
Moldy Popcorn
public text 4 hire!
Posts: 33
|
Post by v3n0mn33dl3 on Nov 20, 2016 4:43:07 GMT -5
You'll have to write a function to convert binary to hex, or even easier, to integer. Something like this should get you started: Yes! BING! "01101111" "128-64-32-16-8-4-2-1" "64+32+8+4+2+1" "111" print chr$(111) Thanks for making me understand what my teacher coudn't 17 years ago!
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Nov 20, 2016 8:47:53 GMT -5
|
|
|
Post by mekanaizer on Nov 20, 2016 19:23:22 GMT -5
Just as a side note you can use BASIC functions to convert stuff around, like:
a$ = Bin$(6) b$ = Bin$(&hf) x$ = Mid$(a$, 28, 4) y$ = Mid$(b$, 28, 4) Print x$ Print y$
NOTE: Saturday BEX forum was down a couple of times, but elusive replied very well. He is a very good person and teacher yes :-)
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Nov 20, 2016 22:23:34 GMT -5
Thanks Mekanizer Found another bug in SBS because of this - the ^ operator doesn't work anymore lol (pow() still does, though).
|
|
|
Post by mekanaizer on Nov 21, 2016 8:59:29 GMT -5
:-)
I found 3 to crash SBS and 1 very nasty, it builds code with var types mixed.
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Nov 21, 2016 9:47:19 GMT -5
:-) I found 3 to crash SBS and 1 very nasty, it builds code with var types mixed. To be fair, I've been asking for your bug report to be emailed to me for months If you can send that over that would be awesome while I'm working on it, otherwise I can only fix them as I stumble across them.
|
|