number to binary

General discussion on mikroBasic PRO for AVR.
Post Reply
Author
Message
uhrmacher
Posts: 14
Joined: 05 Jul 2012 11:18

number to binary

#1 Post by uhrmacher » 28 Mar 2013 14:36

Hi everybody,

i'm struggling a little bit with following problem of binary conversion

2 have to convert two numbers into an binary value to concatenate both 8 bit binaries to a 16 bit binary.

like this: 219 = 11011011 and 7 = 00000111, now i must concatenate both to 0000011111011011
after doing that, the 0000011111011011 must converted to a number, ( = 2011.)

Unfortunately i can't find any to/from binary conversion in the conversion library ( or i do oversee something ;-) )
any advice very appreciated!

best regards

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: number to binary

#2 Post by Dany » 28 Mar 2013 17:45

uhrmacher wrote:Hi everybody,

i'm struggling a little bit with following problem of binary conversion

2 have to convert two numbers into an binary value to concatenate both 8 bit binaries to a 16 bit binary.

like this: 219 = 11011011 and 7 = 00000111, now i must concatenate both to 0000011111011011
after doing that, the 0000011111011011 must converted to a number, ( = 2011.)

Unfortunately i can't find any to/from binary conversion in the conversion library ( or i do oversee something ;-) )
any advice very appreciated!

best regards
Hi,
All numbers are already represented in binary inside variables, so you won't find functions to convert a numerical value into binary...
What you will find are routines to convert variable contents into human readable strings (e.g. strings that show the decimal representation or the hexadecimal one, or even the binary one) and vice versa.

So, the only thing that can be answered here is:
now i must concatenate both
You can do this with:

Code: Select all

  hi(wordvar) = var2 'the 7 in your example
  lo(wordvar) = var1 'the 219 in your example
wherein "wordvar" is your 16 bits variable.

Maybe this article can also be of some interest: http://www.rosseeld.be/DRO/PIC/Numbers% ... Pascal.htm (also valid for mikroBasic, but other code syntax).
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

Post Reply

Return to “mikroBasic PRO for AVR General”