Solved

500: increment hex value

Posted on 2006-11-22
3
1,980 Views
Last Modified: 2008-01-09
Hi all,

Can anyone asap tell me how to increment a hexadecimal value by one.
In decimal it is e.g. x=x+1 but how do I do it in hex?

For example I have:                             $hex_value = "\xC0";
Can I do something along the lines of:   $hex_value = $hex_value + "\x01";     ????????
 will that give me:                                $hex_value = "\xC1";                       ????????????

Many thanks,
0
Comment
Question by:smotbd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 30

Accepted Solution

by:
callrs earned 500 total points
ID: 17997949
<?php
$hex="xC0";
echo dechex(hexdec($hex)+1);
?>
0
 
LVL 30

Expert Comment

by:callrs
ID: 17998018
<?php
$hex="xC0";
echo 'x'.strtoupper(dechex(hexdec($hex)+1));
?>
0
 
LVL 19

Expert Comment

by:Michael701
ID: 17999257
don't over complicate the problem.

$counter=12; // decimal
// you see by setting it to ="\xC0" you made it a string type, not an integer

// if you really want you could set it as
$counter=0xC0;

$counter++;

echo (dechex($counter));

Do you really care about the base of the counter?

Michael
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

622 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question