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?

This is a discussion on *setbase* within the **C++ Programming** forums, part of the General Programming Boards category; i cannot understand what setbase is
can you explain to me? is something about hex dec and oct but i ...

- 07-05-2011 #1

- 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?

- 07-05-2011 #2

- Join Date
- Oct 2007
- Posts
- 24,159

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.

- 07-05-2011 #3

- 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

- 07-05-2011 #4

- Join Date
- Oct 2007
- Posts
- 24,159

- 07-05-2011 #5
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.

- 07-05-2011 #6

- Join Date
- Nov 2010
- Posts
- 65

ohhh yeah

god i have understand now

for some reason i got confused

- Exactly how to get started with C++ (or C) today
- C Tutorial
- C++ Tutorial
- 5 ways you can learn to program faster
- The 5 Most Common Problems New Programmers Face
- How to set up a compiler
- 8 Common programming Mistakes
- What is C++11?
- Creating a game, from start to finish

- How to create a shared library on Linux with GCC - December 30, 2011
- Enum classes and nullptr in C++11 - November 27, 2011
- Learn about The Hash Table - November 20, 2011
- Rvalue References and Move Semantics in C++11 - November 13, 2011
- C and C++ for Java Programmers - November 5, 2011
- A Gentle Introduction to C++ IO Streams - October 10, 2011