Switzerland
Offline
Sr. Member
Karma: 0
Posts: 261
|
 |
« Reply #15 on: March 23, 2012, 10:59:20 am » |
Why do your buffer subscripts start at 1?
Since in the first ([0]) is the adress where the message came from... is 1 << 0 not the same as pow(256,0). Or how can I do it differently?
|
|
|
|
« Last Edit: March 23, 2012, 11:01:36 am by GekoCH »
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #16 on: March 23, 2012, 11:06:36 am » |
1 << 0 is exactly the same value as 2560 The problem lies with the progression 0, 8, 16 ... ?
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Switzerland
Offline
Sr. Member
Karma: 0
Posts: 261
|
 |
« Reply #17 on: March 23, 2012, 11:15:51 am » |
so maybe 24 hmmmm  But still no success or is it still wrong (24)?
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #18 on: March 23, 2012, 11:56:42 am » |
I'm posting this from my phone. I can't see your results, and I'm miles from my Arduinos.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Offline
Jr. Member
Karma: 4
Posts: 68
|
 |
« Reply #19 on: March 23, 2012, 12:40:20 pm » |
Hi, if you are trying to convert from byte array to long integer, simply use the union in the opposite way: Number Out;
Out.barray[0] = b0; Out.barray[1] = b1; Out.barray[2] = b2; Out.barray[3] = b3;
unsigned long val = Out.num
|
|
|
|
|
Logged
|
|
|
|
|
Switzerland
Offline
Sr. Member
Karma: 0
Posts: 261
|
 |
« Reply #20 on: March 24, 2012, 05:41:58 am » |
Hi, if you are trying to convert from byte array to long integer, simply use the union in the opposite way: Number Out;
Out.barray[0] = b0; Out.barray[1] = b1; Out.barray[2] = b2; Out.barray[3] = b3;
unsigned long val = Out.num
Wow thx the union thing worked just great! Finally I do need to send float numbers separated in a 4 byte array with the IEEE-754 Standard. Converting form the bytes to float was easy but the other way round seems harder...
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 314
Posts: 35518
Seattle, WA USA
|
 |
« Reply #21 on: March 24, 2012, 07:56:05 am » |
Finally I do need to send float numbers separated in a 4 byte array with the IEEE-754 Standard. Converting form the bytes to float was easy but the other way round seems harder... Why? It's the same union, with a float added.
|
|
|
|
|
Logged
|
|
|
|
|
Switzerland
Offline
Sr. Member
Karma: 0
Posts: 261
|
 |
« Reply #22 on: March 24, 2012, 11:29:28 am » |
wow you were right hmm this union thing is quite strong have to dig deeper what else it can deliver....
Thx Andy
|
|
|
|
|
Logged
|
|
|
|
|
SF Bay Area (USA)
Offline
Faraday Member
Karma: 78
Posts: 5454
Strongly opinionated, but not official!
|
 |
« Reply #23 on: March 24, 2012, 03:04:03 pm » |
So I tryed this but it doesn't work... long number = 115730; data[0] = (byte)(number >> 24); data[1] = (byte)(number >> 16); data[2] = (byte)(number >> 8); data[3] = (byte)(number);
I don't see anything wrong with the original construction (aside from the ':' vs ';', which I hope is a transcription error.) In what was does it "not work"?
|
|
|
|
|
Logged
|
|
|
|
|
Switzerland
Offline
Sr. Member
Karma: 0
Posts: 261
|
 |
« Reply #24 on: March 25, 2012, 10:09:39 am » |
the value returned was wrong compared to what was expected there fore I wrote it doesn't work...
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 314
Posts: 35518
Seattle, WA USA
|
 |
« Reply #25 on: March 25, 2012, 10:20:39 am » |
the value returned was wrong compared to what was expected there fore I wrote it doesn't work... Could be that your expectations were wrong. No input, no output, no way for us to know whether the code is wrong or your expectations are wrong.
|
|
|
|
|
Logged
|
|
|
|
|
|