Thread: Char to Hex

  1. #1
    Mmm. Purple.
    Join Date
    May 2002
    Posts
    154

    Char to Hex

    Code:
    char buf="ÿ";
    ÿ=0xFF?

    how would i see what it was in hex and visa versa

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Code:
    #include <iostream>
    #include <iomanip>
    
    int main(void){
    
    	std::cout << std::hex;
    	
    	for(int i = 32;i < 128;i++){
    		std::cout << "As Hex - 0x" << i << " ";
    		std::cout << "As Char - " << static_cast<char>(i);
    		std::cout << std::endl;
    	}
    		
    
    }

  3. #3
    Banal internet user
    Join Date
    Aug 2002
    Posts
    1,380
    EDIT: *points down*
    Last edited by BMJ; 10-23-2002 at 12:45 PM.

  4. #4
    Mmm. Purple.
    Join Date
    May 2002
    Posts
    154

    error

    the 2nd way works best for my prog but has errors

    edit: ah! fordy's header fixed it

    But it just outputs what the oringal char was
    Last edited by krappykoder; 10-23-2002 at 12:45 PM.

  5. #5
    Banal internet user
    Join Date
    Aug 2002
    Posts
    1,380
    You may like this better:
    Code:
    #include <iostream>
    
    int main ()
    {
    	char c = 'ÿ';
    	std::cout.flags(std::ios_base::hex | std::ios_base::showbase);
    	std::cout << int(c);
    	
    	return 0;
    }
    There.....
    Last edited by BMJ; 10-23-2002 at 12:46 PM.

  6. #6
    Mmm. Purple.
    Join Date
    May 2002
    Posts
    154

    hehe

    ::ios_base undeclared
    parse error before ::

  7. #7
    Banal internet user
    Join Date
    Aug 2002
    Posts
    1,380
    1) Did you copy and paste the code?
    2) Which compiler/IDE?

  8. #8
    Mmm. Purple.
    Join Date
    May 2002
    Posts
    154

    erra

    Y would it have mattered if i copy pasted?

    dev4

  9. #9
    Banal internet user
    Join Date
    Aug 2002
    Posts
    1,380
    To make sure you didn't make a typo

    I don't understand... it should work!

  10. #10
    Mmm. Purple.
    Join Date
    May 2002
    Posts
    154
    the errors are both on line 6 btw lol

    I was just wandering when can i change my title lol

  11. #11
    Banal internet user
    Join Date
    Aug 2002
    Posts
    1,380
    I'm aware it is in line 6... but I don't understand how ios_base could be undeclared unless you did not #include <iostream>

    (you need 400 posts to change your title - this should not be a motive to spam )

  12. #12
    Mmm. Purple.
    Join Date
    May 2002
    Posts
    154
    I tryed not including it to see if the erorrs were diff and it bails so it must have included it

  13. #13
    Mmm. Purple.
    Join Date
    May 2002
    Posts
    154

    slight error

    slight error: int main ()

    look closely


    ill test it out now

  14. #14
    Banal internet user
    Join Date
    Aug 2002
    Posts
    1,380
    ios_base is a class in the namespace STD... therefore if you are getting that ios_base is undeclared, I would say that you are doing this:
    Code:
    #include <iostream.h>
    Instead of what it should be - this:
    Code:
    #include <iostream>

  15. #15
    Mmm. Purple.
    Join Date
    May 2002
    Posts
    154
    tryed both lol

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. seg fault at vectornew
    By tytelizgal in forum C Programming
    Replies: 2
    Last Post: 10-25-2008, 01:22 PM
  2. Replies: 12
    Last Post: 08-11-2008, 11:02 PM
  3. lvalue error trying to copy between structures
    By emanresu in forum C Programming
    Replies: 2
    Last Post: 11-16-2006, 06:53 AM
  4. Replies: 11
    Last Post: 03-24-2006, 11:26 AM
  5. I'm having a problem with data files.
    By OmniMirror in forum C Programming
    Replies: 4
    Last Post: 05-14-2003, 09:40 PM