Thread: conversion for binary data type

  1. #1

    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:


    #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;



    Here is my output:



  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    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 :-

  3. #3
    Registered User
    Join Date
    Oct 2001
    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];
    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, 10:59 PM
  2. Reading a file with Courier New characters
    By Noam in forum C Programming
    Replies: 3
    Last Post: 07-07-2006, 09:29 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. Replies: 4
    Last Post: 06-14-2005, 05:45 AM