Thread: ASCII values

  1. #1
    Registered User
    Join Date
    Dec 2012
    Posts
    67

    ASCII values

    hey, thanks for looking at my thread.
    I am currently trying to find the ASCII value of my input. I can correctly get my program to display the ASCII value of one character, however I am wondering if it is possible to find the ASCII value of two character.

    For example I know that C is 43 and K is 4b, however would there be a value for CK if they were combined?

    thanks

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    No - they will never be "combined." They will always remain distinct values (0x43 and 0x4B, respectively, in this case).

  3. #3
    Registered User
    Join Date
    Nov 2012
    Posts
    1,393
    The model used for ASCII is one code for one key on the (US) keyboard and hence one character. Two characters such as '^' and 'a' might be conceptually combined to produce the separate character 'â' but this character is not representable as ASCII.

  4. #4
    Registered User
    Join Date
    Dec 2012
    Posts
    67
    ok thank you very much. Would it be possible to sort these ASCII values using bubble sort?

  5. #5
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    Sure. You can compare ASCII values because they are simply numbers. Or you can compare strings - groups of ASCII values and sort 'words'.

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by SDH View Post
    ok thank you very much. Would it be possible to sort these ASCII values using bubble sort?
    You should Google for ascii table, and download either a table, or a picture of a table, and keep it on your desktop for easy reference. It will have all the values (either basic ascii 0-127, or extended for unsigned char with values from 0-255.

    Along with the char symbol, it will also have the octal, hexadecimal, and decimal values of each of the symbols (depending on what table or picture you choose).

    And it's already sorted for you.

  7. #7
    Registered User
    Join Date
    Dec 2012
    Posts
    67
    i am very new to programming, this is what i have been working on and trying to adapt one my lecturer showed me.


    Code:
    {
      int a, b, c;
    
      for (a = (array_size - 1); i > 0; a--)
      {
        for (b = 1; b <= a; b++)
        {
          if (numbers[b-1] > numbers[b])
          {
            c = numbers[b-1];
            numbers[b-1] = numbers[b];
            numbers[b] = c;
          }
        }
      }
    }
    does this code look alright to use?

  8. #8
    Registered User
    Join Date
    Dec 2012
    Posts
    67
    Quote Originally Posted by Adak View Post
    You should Google for ascii table, and download either a table, or a picture of a table, and keep it on your desktop for easy reference. It will have all the values (either basic ascii 0-127, or extended for unsigned char with values from 0-255.

    Along with the char symbol, it will also have the octal, hexadecimal, and decimal values of each of the symbols (depending on what table or picture you choose).

    And it's already sorted for you.
    I am currently sitting with a few books open and one open to an ASCII table, but nice idea will print one out for my desk

  9. #9
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by SDH View Post
    i am very new to programming, this is what i have been working on and trying to adapt one my lecturer showed me.
    does this code look alright to use?
    You can print up your own ascii table, sure. And your character set may be slightly different from the ones in the standard ascii table - especially above 127. You'll notice that the character set for forums will also be slightly different than your own - again, especially above 127.

    Your code as it stands won't work, but I'll help you get one that will work, if you like.

    Note that when you paste in code, paste it in as PLAIN TEXT, instead of colored. The forum will color the code properly, and give it a better font, etc. With the colors you posted, it's difficult to read.
    Last edited by Adak; 01-09-2013 at 10:36 AM.

  10. #10
    Registered User
    Join Date
    Dec 2012
    Posts
    67
    thank you very much Adak, would really appreciate any help with the bubble sort. What is wrong the bubble sort I have posted, so I can learn from my mistakes.

    Note that when you paste in code, paste it in as PLAIN TEXT, instead of colored. The forum will color the code properly, and give it a better font, etc. With the colors you posted, it's difficult to read.
    thanks sorry for the hindrance.

  11. #11
    Registered User
    Join Date
    Dec 2012
    Posts
    67
    i have had a look at my code again - simplified it down by using letters instead of words, will change them once I have got it working properly. however when I run it, it says there is a problem on line 16.
    Code:
     #include <stdio.h> 
    int main( void )
    {
         int numb[5];
         int i,j;
         int temp;
         
         printf("enter 5 numbers\n", i);      
        
         for ( i=0;i<=4; i++)
         scanf( "%d", &j);
             { 
                for ( i=0; j<=3; i++)
                   {
                      if (j=i+1; j<=6; j++)
                      {
                          temp = numb[i];
                          numb[i] = numb[j];
                          numb[j] = temp;
                      }   
                   }  
        
             }
     }

  12. #12
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > for ( i=0; j<=3; i++)
    > if (j=i+1; j<=6; j++)
    You have 5 numbers, so where did 3 and 6 come from?

    If you have
    int array[N];

    Then the usual form of the for loop is to write
    for ( i = 0 ; i < N ; i++ )

    Using <= and subtracting 1 from the dimension yourself just leads to confusion.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  13. #13
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Typing out an entire program and hitting compile when you're done is guaranteed to cause massive headaches.

    Tip 1: Compile often when writing code. This way, if you make a syntax error, you know it is likely be caused by something you recently added, narrowing the focus for troubleshooting. This will also encourage writing complete "skeleton" code (i.e. making sure all your loop brackets are in place) before filling in the details later on.

    Tip 2: Break the problem into smaller, manageable problems, and solve them one by one. In your case, I'd follow these steps:

    - Write a program that prints five numbers from an array to the screen
    - Add code to receive numbers from the user before printing the array to the screen
    - Implement your sorting routine
    - (For quick debugging, don't be afraid to put temporary print statements in your loops to see what your variables are doing)

    The trick is to make sure each little piece is working as expected before moving on to the piece.

    I'd also recommend reading the following link - I've echoed some of the message in this post, but it's a lot more clear to see visually.

    A development process

  14. #14
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by Matticus View Post
    No - they will never be "combined." They will always remain distinct values (0x43 and 0x4B, respectively, in this case).
    The standard allows it, although the meaning is implementation defined:

    Code:
    short int multiple = 'CK';
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  15. #15
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Quote Originally Posted by brewbuck View Post
    The standard allows it, although the meaning is implementation defined...
    Though allowed by the standard, wouldn't such an example fall outside the scope of what is considered "ASCII" (as per the original question)? If so, then I should have been more clear with my original statement.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ascii values
    By caliber005 in forum C Programming
    Replies: 6
    Last Post: 05-18-2011, 03:16 PM
  2. ASCII values help
    By Grant_Searle in forum C Programming
    Replies: 5
    Last Post: 10-22-2010, 09:01 AM
  3. Using ASCII Values
    By ga836044 in forum C Programming
    Replies: 7
    Last Post: 03-17-2004, 01:31 AM
  4. adding ASCII values
    By watshamacalit in forum C Programming
    Replies: 1
    Last Post: 12-26-2002, 07:16 PM
  5. Testing for ASCII values?
    By csmatheng in forum C Programming
    Replies: 1
    Last Post: 02-19-2002, 02:22 PM