Solved

500: increment hex value

Posted on 2006-11-22
3
1,922 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
  • 2
3 Comments
 
LVL 30

Accepted Solution

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

Expert Comment

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

Expert Comment

by:Michael701
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
.htaccess file settings 4 32
PHP Sum Column in Table 3 26
PHP string issue 5 16
What is the Best Editor for PHP Development ? 5 24
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now