Results 1 to 5 of 5

Thread: Converting Char to Int in PHP

  1. #1
    Join Date
    Nov 2009
    Posts
    518

    Converting Char to Int in PHP

    I am student of computer science and creating a small tutorials of the conversion of data types,Nearly,I have done all this but getting some problem regarding the conversion of character value to integer values.Is there any way to convert a character value into integer value.so please tell me specially for PHP programming .

    Thanks.

  2. #2
    Join Date
    Oct 2005
    Posts
    2,393

    Converting Char to Int in PHP

    There are so many ways you can use to convert a character value in integer value.Everything is depends on your logic,how much you can expand and concentrate your mind to create the logic to convert the types and value of the variable .

    But if you have defined and assigned a character value other than the Number means,the variable value which you need to convert should be defined and assigned as like -

    Char = '3' ;

    If you assigned some letter and all as a value then the conversion can't be happened as you think.

  3. #3
    Join Date
    May 2008
    Posts
    2,389

    Converting Char to Int in PHP

    Converting Char to Int in PHP

    You can use this code which can help you to perform the conversion want to perform,use this below code -


    Code:
    n = atoi(&c);
    Where n is an integer value and the atoi is an function which will convert the variable specified and C is the character variable which needs to be converted.

  4. #4
    Join Date
    Feb 2008
    Posts
    1,852

    Converting Char to Int in PHP

    If you have assigned a character value in the character variable and ready to convert it into integer then you have to use some advance techniques and tools provided by PHP programming .

    you can one of the suggested code below which can help you to find your destination .

    char dest='a';
    int conv=(int)dest;

    dest variable is assigning a character value and conv is an integer value,the second statement can help you for converting actual string into integer value.

  5. #5
    Join Date
    Jan 2008
    Posts
    1,521

    Converting Char to ASCII Int in PHP

    You can convert a character value into its own ASCII value.The code shown below which can guide you to find the ASCII of the character variables -

    Code:
    char* x = "abc";
        int k;
      
        k = *(int*)x; /* assigns 0x434241 on little-endian machines with 32-bit ints
    The character value would be assigned in the variable X and makes and internal array which is performed by second statement covered with the bracket will take the values according to array and then supplied to the integer variable named K.

Similar Threads

  1. Array of char and int
    By Jensen Ackles in forum Software Development
    Replies: 5
    Last Post: 23-03-2010, 09:50 AM
  2. Converting string to char
    By Abdullah30 in forum Software Development
    Replies: 3
    Last Post: 03-09-2009, 11:09 PM
  3. How to convert char to hex
    By ASHER in forum Software Development
    Replies: 3
    Last Post: 26-08-2009, 06:49 PM
  4. How do i clear char array in c++
    By B_Hodge in forum Software Development
    Replies: 3
    Last Post: 16-05-2009, 09:35 AM
  5. Converting Char value to ASCII number, C++
    By Gemstone29 in forum Software Development
    Replies: 2
    Last Post: 22-04-2009, 08:30 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,469,752.01863 seconds with 16 queries