Solved

500: increment hex value

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP strings vs array errors 13 33
Decrypt string by php 7 47
Creating Functions in phpMyAdmin 8 26
Ajax and PHP 9 30
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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 count occurrences of each item in an array.

828 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