Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3368: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3370: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3371: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3372: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
OrbWorks Community Forum • View topic - 2 chars to hex value... simple but how ?
Page 1 of 1

PostPosted: Mon Nov 18, 2002 5:21 am
by woale
Let's say you have 2 character variables called msb and lsb.
Both can range from '0' to '9' or from 'A' to 'F'.
Now, how can you put those 2 characters into 1 character containing the hexadecimal value msb and lsb ?

//Example :
char msb='6';
char lsb='E';
char xval;
xval=???????; // How can you put msb and lsb in xval ?
puts(hex(xval)); // In order to get 0x6E put on screen,
puts((int)xval); // or the value 110 (=hexadecimal 6E),
puts(xval); // or the value 'n' (=asci code 110).

This seems very simple, but I've been searching for hours on this little issue and cannot come up with anything decent.
Does anyone have a clue ?

PostPosted: Mon Nov 18, 2002 5:53 am
by soinsg
PocketC tends to stick "0x" on the front of hex strings. So maybe this will work:

//Untested
char msb='6';
char lsb='E';
char xval;
string tmp;

tmp = msb + (string)lsb;

tmp = hex(msb);
tmp = strright(tmp, 2);

xval = (char)tmp;

//More likely to work
tmp = msb + (string)lsb; //Cast incase it adds them
tmp = hex(tmp);
xval = (char)tmp; //Hex to char, maybe stick an (int) in too?

PostPosted: Mon Nov 18, 2002 8:22 am
by guy
The easiest way to do it is:

char cResult ;

cResult = "0x" + msb + lsb ; // Automatic type conversion

This will work if msb and lsb are chars or strings because
the subexpressions are evaluated from left to right and
the type remains as a string.

To be more rigorous you can use:

cResult = "0x" + (string) msb + (string) lsb ;

Casts in PocketC are evaluated at runtime, so there will
be a small overhead in the second option.



Guy
[url]mailto:pcform@pcform.net[/url]
http://www.pcform.net
PocketC CE API interface: http://www.networkdynamics.net/PCForm.html#library
PCForm and CE API forum: http://www.networkdynamics.net/forum

PostPosted: Mon Nov 18, 2002 1:57 pm
by woale
<blockquote id="quote"><font size="1" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote"><i>Originally posted by guy</i>
<br />The easiest way to do it is:

char cResult ;

cResult = "0x" + msb + lsb ; // Automatic type conversion

<hr height="1" noshade id="quote"></blockquote id="quote"></font id="quote">

You see, I knew it had to be simple...
still, I needed to declare cResult as a string, otherwise I kept getting '0'.

Thanks a lot Guy and Soinsg.

PostPosted: Mon Nov 18, 2002 5:01 pm
by soinsg
Oops, I feel a bit silly, I just realised I posted in the CE forum, but I guess CE has a hex() function too. And I fed a hex string into hex()!