Thread: the value of a char

  1. #1
    wierd guy bart's Avatar
    Join Date
    Aug 2001
    Posts
    87

    the value of a char

    I know ive seen this somewhere, but i can't find it back. how do you change the binary value of a char. for instance, the binary value of 'a' + 1 to get 'b'. (I know the example isn't so useful unless you want to list the alfabet)

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    88
    the binary value is difficult to calculate - if you want I can look for a piece of code and post it - but i don't remember the code *gg*

    but if you want to list the alphabet you better use the ascii code of the chars

    for example

    for(int i='a';i<='z';++i)
    cout<<i<<"\n";
    Hope you don't mind my bad english, I'm Austrian!

  3. #3
    wierd guy bart's Avatar
    Join Date
    Aug 2001
    Posts
    87
    let me put it differntly, the ascii value of a charactar, for instance 'a' is 97, or 60 in hexidecimal. but how do you say, the ascii value of the character -20

  4. #4
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    There's a way you can print out the value of it with a binary form. I can do it in C, but not sure in C++. There has to be a way in C++, though.
    1978 Silver Anniversary Corvette

  5. #5
    Registered User
    Join Date
    Nov 2001
    Posts
    66
    I don't know if this is what you are looking for but if you are trying to find the ascii value of hex 0x-20 there isn't one Idon't believe ascii and hex are only postive.

    Ryan

    (I find that you get the most help from zen)

  6. #6
    Registered User
    Join Date
    Sep 2001
    Posts
    164
    I believe the '-' sign shouldn't be there, right?

    char a = 20; //a now contains 20
    cout << a; //This will print out the character
    // Gliptic

  7. #7
    Registered User
    Join Date
    Dec 2001
    Posts
    28
    There are no -ve ASCII characters. If you are able to view any ascii characters by, say doing a cout << (chr) -20;, it'd be compiler dependent, and would only return the normal ASCII character of the number calculated by remainer of -20 mod 256.

  8. #8
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Try explicit conversion. THe syntax:

    new_variable = (new_type)old_variable;

    I've tried something like this before, and it didn't work, but this is a start, and may work (after all, I sucked at debugging when I did this the last time... Try it.)

  9. #9
    Registered User
    Join Date
    Sep 2001
    Posts
    164
    -20 as an unsigned byte is (256-20) = 236. 236 is one of the extended characters: . Cool! It's the infinite symbol!

    (EDIT) Ohh, it converted to Unicode. Crap (/EDIT)
    // Gliptic

  10. #10
    wierd guy bart's Avatar
    Join Date
    Aug 2001
    Posts
    87
    thanks, sean reminded me.
    the code was
    Code:
    (int)'a'

  11. #11
    Registered User
    Join Date
    Dec 2001
    Posts
    421
    how do you change the binary value of a char

    looks to me that the answer you wanted was very different to the question you asked!

    int x = (int)'a';

    is very different to 'changing' a binary value!

    U.
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

  12. #12
    wierd guy bart's Avatar
    Join Date
    Aug 2001
    Posts
    87
    how would you reccomend asking the question.

  13. #13
    Registered User
    Join Date
    Dec 2001
    Posts
    421

    Post

    I probably would have said:

    "how do i store the ascii value of a char in an integer variable?"

    that would have made it perfectly clear

    But hey, as long as you have what you want... who cares?!

    U.
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 06:02 AM
  2. Sorting Linked Lists
    By DKING89 in forum C Programming
    Replies: 6
    Last Post: 04-09-2008, 07:36 AM
  3. code condensing
    By bcianfrocca in forum C++ Programming
    Replies: 4
    Last Post: 09-07-2005, 09:22 AM
  4. Passing structures... I can't get it right.
    By j0hnb in forum C Programming
    Replies: 6
    Last Post: 01-26-2003, 11:55 AM
  5. String sorthing, file opening and saving.
    By j0hnb in forum C Programming
    Replies: 9
    Last Post: 01-23-2003, 01:18 AM