Breaking a binary stream

This is a discussion on Breaking a binary stream within the C++ Programming forums, part of the General Programming Boards category; I am new to programming, I have a task which I have to do the following 1. I have to ...

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    2

    Breaking a binary stream

    I am new to programming, I have a task which I have to do the following

    1. I have to read in a text file containing characters as well as space, and I don't know why I can read in the characters only but not space.

    2. after this I convert my data into double type, then convert into binary, and store them into an array with type double/char, and get something like below (2 characters in this case)

    a = [01101101 10110111]

    a can be either in type char or double, and has 2 cells.
    and I want to convert it into

    b= [0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1]
    so now b is an array with 16 cells, and type is double

    so what i am really doing is to break my message into binary stream

    how should I perform it please?

    Many thanks in advance

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,340
    1. Are you using operator >> to read in the data? It skips whitespace by default. If you're reading one character at a time, use cin.get(). If you're reading in doubles, you can also use >> to read directly into a double instead of converting it yourself.

  3. #3
    Registered User
    Join Date
    Dec 2009
    Posts
    2
    but if I store the ACSII in array like in a, how can I break them into b please?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 0
    Last Post: 11-04-2006, 10:07 AM
  2. Help! About text stream and binary stream
    By Antigloss in forum C Programming
    Replies: 1
    Last Post: 09-01-2005, 08:40 AM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Tutorial review
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 03-22-2004, 08:40 PM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM

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