0 registered members (),
1,089
guests, and 10
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
convert DEC to HEX
#383701
09/24/11 04:23
09/24/11 04:23
|
Joined: Aug 2002
Posts: 164 Houston
Nicholas
OP
Member
|
OP
Member
Joined: Aug 2002
Posts: 164
Houston
|
I am using the serial port commands from http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=280484&Searchpage=1&Main=34315&Words=%22port_write_bytes%22&Search=true#Post280484 and need to get it to work apparently by converting my numbers to hex.
How can I convert a variable or char to a HEX format (eg 100 = 0x64)
thanks... or if you know why/how the serial code won't accurately accept my numbers. (I have the incoming byte setup as an int on the MCU side, incomingByte = Serial.read();)
Black holes are where God divided by zero.
|
|
|
Re: convert DEC to HEX
[Re: Nicholas]
#383704
09/24/11 05:51
09/24/11 05:51
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
Expert
Joined: Apr 2007
Posts: 3,751
Canada
|
There is no direct conversion between hexadecimal and binary, the reason is that the underlying data structure, this is your char or var or whatever, represents the data as binary, you can't force a representation model onto the variable but it will rather convert every decimal or hexadecimal value you assign it to, to a binary representation.
Shitlord by trade and passion. Graphics programmer at Laminar Research. I write blog posts at feresignum.com
|
|
|
Re: convert DEC to HEX
[Re: rojart]
#383726
09/24/11 15:20
09/24/11 15:20
|
Joined: Aug 2002
Posts: 164 Houston
Nicholas
OP
Member
|
OP
Member
Joined: Aug 2002
Posts: 164
Houston
|
Thanks, I thought there should be some conversion thing. How do I get that into the byte though? char cStr[256]; int iDec = 100; byte bByte; sprintf(cStr, "%x", iDec); bByte = cStr; //bByte should contain 0x64
That's what I tried, but it doesn't seem to work. I tried reading up on the sprintf, but there's nothing about it in the manual. I assume it's a C thing. thanks
Black holes are where God divided by zero.
|
|
|
Re: convert DEC to HEX
[Re: Aku_Aku]
#383754
09/25/11 01:41
09/25/11 01:41
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Hiya guys, long time no see. Its been 6 months since Ive even touched Gamestudio, so Im a bit rusty... But Im trying to get back into it again, just to validate the money I just spent upgrading to A8...
Hey Nic, I see you are trying to implement my old port_io.h header. "port_write_bytes" doesnt need hex data, it just sends binary (byte) data starting with the first byte found at the data address.
So the need for any hex to dec conversion is un-necessary as far as I can see...
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: convert DEC to HEX
[Re: MrGuest]
#383778
09/25/11 10:40
09/25/11 10:40
|
Joined: Oct 2004
Posts: 900 Lgh
rojart
User
|
User
Joined: Oct 2004
Posts: 900
Lgh
|
@Nicholas Here is another sample that convert dec to bin, but as EvilSOB already said that there is no need conversion. @EvilSOB Welcome back!
#include <default.c>
#include <stdio.h>
void iDecBin(int n) {
if (!n) {return;
}else{
iDecBin(n/2);
printf("%d", n%2);
}
}
void main() {
wait(1);
char cStr[256];
int iDec = 100;
sprintf(cStr, "%x", iDec);
printf("dec %d in hex is 0x%s\n", iDec, cStr);
iDecBin(iDec); // dec 100 in bin is 1100100
}
|
|
|
Re: convert DEC to HEX
[Re: Aku_Aku]
#383786
09/25/11 12:32
09/25/11 12:32
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Another off-topic... Hi all! Thanks for the support! BTW, if any of you guys had any issues getting Gamstudio running in Windows 7, specifically A8, please check my posting in the upgrades THREAD ... I hope you can help.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
|