Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 08:01 19 Apr 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : str2bin not behaving?

Author Message
johngill
Newbie

Joined: 22/09/2020
Location: United Kingdom
Posts: 34
Posted: 03:40pm 04 Mar 2021
Copy link to clipboard 
Print this post

Hi all,

I don't know if it's me being a plantpot, but as far as I understand it, this should give me the value 22:

print str2bin(uint8,"00010110",BIG)

I've put eight 0s and 1s in the string, and it's still giving me string length error. Am I doing something wrong or is this a firmware bug?

I'm on 5.07.00b19

thanks!
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8566
Posted: 03:52pm 04 Mar 2021
Copy link to clipboard 
Print this post

str2bin and bin2str are used for packing the binary representation of a number into a string. The normal use is for writing binary to and from a file or for converting a string containing binary values such as received from some I2C devices into a MMBasic number. For your usage you need to look at functions like VAL and BIN$
 
johngill
Newbie

Joined: 22/09/2020
Location: United Kingdom
Posts: 34
Posted: 03:57pm 04 Mar 2021
Copy link to clipboard 
Print this post

ok, thanks, my misunderstanding.
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3008
Posted: 03:59pm 04 Mar 2021
Copy link to clipboard 
Print this post

Interestingly, on the F4, this causes a lockup, necessitating a reset.

? str2bin(uint8,"0001011000000000")
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
toml_12953
Guru

Joined: 13/02/2015
Location: United States
Posts: 324
Posted: 05:38pm 04 Mar 2021
Copy link to clipboard 
Print this post

  johngill said  Hi all,

I don't know if it's me being a plantpot, but as far as I understand it, this should give me the value 22:

print str2bin(uint8,"00010110",BIG)

I've put eight 0s and 1s in the string, and it's still giving me string length error. Am I doing something wrong or is this a firmware bug?

I'm on 5.07.00b19

thanks!


Try PRINT VAL("&B"+"00010110")
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024