Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

500: increment hex value

Posted on 2006-11-22
3
Medium Priority
?
1,999 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 2000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

972 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