Ask about how to change from int to unsigned char

This is a discussion on Ask about how to change from int to unsigned char within the C++ Programming forums, part of the General Programming Boards category; I want to change from int to unsigned char. Example: int i = 50, j = 512; I want to ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    68

    Lightbulb Ask about how to change from int to unsigned char

    I want to change from int to unsigned char.

    Example:

    int i = 50, j = 512;

    I want to change from number 50 to unsigned char '5' and '0' and change from number 512 to unsigned char '5' , '1' and '2'
    or can change abitary number to unsigned char. If you know how to do that please tell me.Thank you.

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    PHP Code:
    #include <iostream.h>
    #include <stdio.h>

    int main()
    {
        
    char digits[20] = {0};
        
    sprintf(digits,"%ld",512);
        for(
    int i 0;20;i++)
        {
            if(
    digits[i] == 0)
                break;
            
    cout<<digits[i]<<endl;
        }
        
    cin.get();
        return 
    0;

    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 10:42 PM
  2. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM
  3. Personal Program that is making me go wtf?
    By Submeg in forum C Programming
    Replies: 20
    Last Post: 06-27-2006, 01:13 AM
  4. Working with random like dice
    By SebastionV3 in forum C++ Programming
    Replies: 10
    Last Post: 05-26-2006, 10:16 PM
  5. Need help understanding info in a header file
    By hicpics in forum C Programming
    Replies: 8
    Last Post: 12-02-2005, 12:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21