binary math - add three 8 bit variables
gtslabs
Posts: 40
How can I divide a 24 bit value into 3 8 bit variables so I can read and write them to 24 bit registers?
Is there any example code how to do this since the word is the largest at 16 bits?
Would this fall under the "big endian" and "little endian" format?
Thanks
Steve
Is there any example code how to do this since the word is the largest at 16 bits?
Would this fall under the "big endian" and "little endian" format?
Thanks
Steve
Comments
"big endian" vs. "little endian" refers to whether the most significant byte comes first or the least significan byte comes first respectively.
I have been using the SHIFTIN and SHIFTOUT commands but not figured how to send it the 3 sets of 8 yet.
I have this VB code to convert decimal to 24 bit binary that I was thinking of using to put on the stamp.
Public Function dec24binFunc(ByVal x As Double) As String
··· Dim p As Double
··· bits = ""
··· p = 1
··· i = 0
··· Do Until i >= 23
······· i = i + 1
······· If x And p Then bits = "1" + bits Else bits = "0" + bits
······· p = p * 2
······· ' This puts a dot for every 8 bits for better reading
······· If (i Mod 8) = 0 Then bits = "." + bits
··· Loop
··· If i > p Then bits = "1" + bits Else bits = "0" + bits
··· dec24binFunc = bits
End Function
How would I read·the·3 8-bit·numbers using the SHIFTIN command?
MidByte VAR BYTE
HighByte VAR BYTE
SHIFTIN PortNum, [noparse][[/noparse]LowByte/8, MidByte/8, HighByte/8]
You cannot use LOWBYTE and HIGHBYTE as variable names. For SHIFTIN you will need 3 parameters following the command besides the data. The slashes should be backslash, not forward slash, though you don’t need them for 8 bits as that is the default. Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support