Page 1 of 1

Int -> String HELP HELP

Posted: Mon Aug 02, 2004 11:57 pm
by mshita
How do I convert an integer to ascii?

Like I have $test = 0x55. How do I get $test_string = "T"?

Posted: Tue Aug 03, 2004 12:34 am
by markl999
0x55 is the letter U by the way ;)

Code: Select all

<?php
$test = 0x55;
echo chr($test);
?>

Posted: Tue Aug 03, 2004 12:37 am
by mshita
Ah, cool. Thanks :)

Oh, and yeah.. U not T lol

Posted: Tue Aug 03, 2004 12:57 am
by mshita
How about if it is a non-ascii character?

I have $test = 0x23;

But when I do the chr($test) it comes out to 0x00 in my hex editor.

Posted: Tue Aug 03, 2004 10:52 am
by feyd
0x23 = 35 = '#'

Posted: Tue Aug 03, 2004 2:11 pm
by mshita
okay, maybe 0x23 was a bad example, but I want the number can be anything from 0x00 to 0xFF. But chr($test) is showing all those as 0x00.

Here is the code

Code: Select all

function describe()
{
	global $text;
	global $text_descriptor;
	global $text_length;
	global $start;
	
	$text_raw = array_values(unpack('C*', $text));
	$text_raw .= "        ";
	$text_raw = substr($text_raw, 0, ;
	$start = 0;
	
	for ($i = 0; $i < 8; $i++)
	{
		$temp = $text_raw[$i] & 0x01;
		$start = $start | ($temp << $i);
		$text_descriptor[$i] = 0;
		
		echo (pack('N*', $text_descriptor[$i])."<br>");
	
		for ($j = 0; $j < 8; $j++)
		{
			if ($j < 7)
			{
				if (($text_raw[$i] & (1 << $j)) == (($text_raw[$i] & (1 << ($j + 1))) >> 1))
				{
				}
				else
				{
					$text_descriptor[$i] |= 1 << ($j);
				}
			}
			else
			{
				if (($text_raw[$i] & 0x01) == (($text_raw[$i] & 0x80) >> 7))
				{
				}
				else
				{
					$text_descriptor[$i] |= 1 << ($j);
				}
			}
		}
	}
	
	
	$ret_string = chr($start);
	echo ("Start -> ".$ret_string." <br>");
	
	for ($i = 0; $i < $text_length; $i++)
	{
		$ret_string = $ret_string.chr($text_descriptor[$i]);
		echo ($ret_string."<br>");
	}
		
	return $ret_string;
}

feyd | flipped

Code: Select all

to

Code: Select all

[/color]