Thread: setbase

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    65

    setbase

    i cannot understand what setbase is
    can you explain to me? is something about hex dec and oct but i dont understand
    i know that hex is from 0 to f
    dec 0 to 9
    and
    oct 0 to 7
    does it have to do about this?

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Simply put, std::setbase sets an output base. Which means that when you output a number, it converts that to the base you specified and outputs that instead of what you inputted.
    For example, use std::setbase(16) and output 255, and you will get FF. Output 0xFF and you will get... that's right, FF.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Nov 2010
    Posts
    65
    but the exercise im reading tells 9 in base 10, is 11 in base 8
    if its that you are telling what this sentence means

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    The number "9" in base 10 would be "10" in base 8.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    The decimal base we know and love is built on powers of 10: one, ten, hundred, thousand. The binary base is built on powers of 2: one, two, four, eight. So 1101(2) is eight+four+one=thirteen. Similarly octal is built on powers of eight and hex on powers of 16.

  6. #6
    Registered User
    Join Date
    Nov 2010
    Posts
    65
    ohhh yeah
    god i have understand now
    for some reason i got confused

Popular pages Recent additions subscribe to a feed