conversion for binary data type

This is a discussion on conversion for binary data type within the C++ Programming forums, part of the General Programming Boards category; Is there a binary parameter for 'setiosflags' ??? The output show that the decimal number and hex number print... But ...

  1. #1
    DMaxJ
    Guest

    Angry conversion for binary data type

    Is there a binary parameter for 'setiosflags' ??? The output show that the decimal number and hex number print... But the binary parameter yields an off the wall answer.

    Here is my code:

    #include<stdio.h>
    #include<ctype.h>
    #include<iostream.h>
    #include<stdlib.h>
    #include<iomanip.h>

    #define MAXSTRING 8

    void main(void)
    {
    int number = 1001;

    cout << setiosflags(ios::dec) << number << endl ;
    cout << "\t"<< setiosflags(ios::hex)<< number << endl;
    cout << "\t"<< setiosflags(ios::binary)<< number << endl;

    exit(0);





    }


    Here is my output:


    '1001'
    '3e9'
    '0x3e9'

    thanks

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    i'm pretty sure that ios::binary cannot be used like that.It is not a format specifier but instead an openmode type.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    You may have to use itoa(). I tried:
    cout << setbase(2) << number << endl;

    but it did not print in binary. For itoa(),

    char str[33];
    itoa(number,str,2);
    cout << str << endl;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can you check what is wrong with this code
    By Ron in forum C++ Programming
    Replies: 4
    Last Post: 08-01-2008, 11:59 PM
  2. Reading a file with Courier New characters
    By Noam in forum C Programming
    Replies: 3
    Last Post: 07-07-2006, 10:29 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 11:03 AM
  5. Replies: 4
    Last Post: 06-14-2005, 06:45 AM

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