Solved

500: increment hex value

Posted on 2006-11-22
3
1,945 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
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

813 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

16 Experts available now in Live!

Get 1:1 Help Now