| 
    
Forum Index : Microcontroller and PC projects : MMBasic bit operator's.... and two's compliment
| Author | Message | ||||
| DigitalDreams Newbie Joined: 03/05/2025 Location: United KingdomPosts: 34  | 
    
    
 Trying to invert an 8-bit binary number and display the result. Dim as integer a A=57 Print bin$(a,8) Working as expected.... Now add A=inv(a) Print bin$(a,8) Works as expected (inverting all bits) YET Displays ALL 64 bits not the low 8 !?!? On the subject, do we have any commands to handle (convert, display) 8-bit two's compliment binary numbers or do we have to manually manipulate ?. Yes I'm trying to read and write two's compliment binary numbers on the i2c bus. Edited 2025-07-23 00:55 by DigitalDreams  | 
  ||||
| twofingers Guru Joined: 02/06/2014 Location: GermanyPosts: 1662  | 
    
    
 do you mean something like that? a=INV(57) And 2^8-1 Regards Michael causality ≠ correlation ≠ coincidence  | 
  ||||
| matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 10554  | 
    
    
 BIN2STR$  | 
  ||||
| PhenixRising Guru Joined: 07/11/2023 Location: United KingdomPosts: 1600  | 
    
    
   I love these functions  ![]() Edited 2025-07-23 02:45 by PhenixRising  | 
  ||||
| DigitalDreams Newbie Joined: 03/05/2025 Location: United KingdomPosts: 34  | 
    
    
 BIN2STR$ Not entirely useful. I take it the i2c commands strip higher bits from 64 bit integers and only deal with the low 8 ?  | 
  ||||
| Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 8262  | 
    
    
 Very likely. AFAIK the I2C system in MMBasic is strictly byte-orientated. If you wanted to send anything longer you would have to split into bytes first. You could send four elements of an array to send a 64-bit integer that way. Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs  | 
  ||||
| matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 10554  | 
    
    
 BIN2STR$ and STR2BIN are specifically designed for things like I2C communication Suppose you want to send a 16-bit signed integer to a I2C device a$=bin2str$(int16,myint) i2c send addr%,0,2,a$ If it wants the bytes the other way round a$=bin2str$(int16,myint,BIG) i2c send addr%,0,2,a$ Same when receiving from i2c - just use str2bin I wrote these functions specifically to make I2C comms to all sorts of devices easy.  | 
  ||||
| Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 8262  | 
    
    
 Ah, so the I2C data is still sent as bytes, but as string characters rather than as elements of a single-dimensional array. :) Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs  | 
  ||||
| DigitalDreams Newbie Joined: 03/05/2025 Location: United KingdomPosts: 34  | 
    
    
 Suppose you want to send a 16-bit signed integer to a I2C device a$=bin2str$(int16,myint) i2c send addr%,0,2,a$ If it wants the bytes the other way round a$=bin2str$(int16,myint,BIG) i2c send addr%,0,2,a$ Same when receiving from i2c - just use str2bin I wrote these functions specifically to make I2C comms to all sorts of devices easy. Ah, I see !. Thanks for clarifying Peter....  | 
  ||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025   |