Directly converting binary inputs into decimal?
Passerby
Posts: 17
For example, if I have something like this:
a = 1
b = 0
c = 1
d = 0
a being number 8, 1010 = 10.
is there a code out there which helps converts these values?
cheers.
a = 1
b = 0
c = 1
d = 0
a being number 8, 1010 = 10.
is there a code out there which helps converts these values?
cheers.
Comments
If you have a variable defined as a nibble (4 bits) called X, you can say:
X.bit3 = a
X.bit2 = b
X.bit1 = c
X.bit0 = d
At this point, X is 10.
You can also do: X = ((a << 1 + b) << 1 + c) << 1 + d
Therefore, x would have the value of 10, right?
So, meaning that if the binary is an 8 bit value now, I'll just have to extend the coding to x.bit7 = value, and change the variable type to Byte? [noparse]:)[/noparse]
Post Edited (Passerby) : 3/5/2009 6:10:43 AM GMT
x VAR byte
x.bit0=h
x.bit1=g
....
x.bit7=a
Where are you going with this? Your subject line is "directly converting binary INPUTs to decimal". It may be as easy as,
x = INL
That reads all 8 input pins, p0 to p7, directly into the variable x.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
/mock up code for input 8
This is just a mock up code, I know it will not work.
This is just a rough "sketch" of my idea. [noparse]:)[/noparse]
Post Edited (Passerby) : 3/6/2009 5:07:57 AM GMT