reading and writing in bits


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: reading and writing in bits

  1. #1
    Join Date
    Oct 2005
    Posts
    17

    reading and writing in bits

    I am new to java, and to be honest, programming. And I was looking at the archive on bitinputstream and bitoutputstreams, and I was wondering if the available source code that is available on this link: http://archive.devx.com/java/free/ar...52002_code.zip
    is a non-standard class like textio where I can import it into a program where I will implement its features. Such as reading and writing single bits without having to worry about resetting the buffer like it shows on :
    http://archive.devx.com/java/free/ar...gt052002-1.asp.
    I understand how the buffer works; it is just that I don't want to worry about figuring out how to write it into code. I have no problem with the fact of just reading bits and writing bits as it is shown on the previous link, or is it more complicated than that. You're input would be much appreciated, thank you.

  2. #2
    Join Date
    Jul 2005
    Location
    SW MO, USA
    Posts
    299
    Not sure that you can read/write less than 8 bits (byte) at a time.
    As a new comer, why not study Sun's classes first?

    What is your question?

  3. #3
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    Pretty advanced stuff for someone who is not only new to Java but also new to programming.

    Why are you wanting to address individual bits?

    I follow the discussion in the articles you referenced, but I can't think of a way to accomplish the tasks they discuss without re-creating what the authors have already implemented. You cannot read bits at a time from a stream - the smallest you can read is a byte which can then be converted to bits as the authors discuss. Can store in a BitSet. Once the input is converted to a BitSet you can address a particular bit ...

  4. #4
    Join Date
    Oct 2005
    Posts
    17
    the article states that you can manipulate individual bits within a buffer that is a byte in length, and when you are finished, the buffer is flushed and is written as a byte to file. The classes allow you to read and write individual bits, but lets say you reach the end of your manipulation. And there's only three bits that you manipulated within the buffer; when the buffer is flushed, five padding bits are added to the file (which are five 0's). I believe the article states that the classes don't allow you to write a bit at a time but allow you to manipulate a file so that it is like doing so. but you would have to keep up with the padding bits at the end of your manipulation. On the link that i gave, it stated that you could read bits sequentially such as, int b0 = bin.readBit(); for the first bit. I was wondering if i could do a b++ sort of thing where everytime i write b = bin.readbit(), in the code it would allow me to read the bits sequentially all the way up to the end of the file. where I would write:
    for (b = bin.readbit())
    if b = 1
    blah blah blah
    elseif
    blah blah blah
    for (b = bin.readbit())
    if b = 1
    blah blah blah
    elseif
    blah blah blah
    where the next (b = bin.readbit()) is the next bit being read and blah blah blah is any code i write for that condition. I suppose before i write that code I would make for (b = 0, b < eof, b++) under which the rest of the could is written.

  5. #5
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    Have you looked at the BitSet class?

  6. #6
    Join Date
    Oct 2005
    Posts
    17
    i have looked at it in c++ but i had difficulty with it. I suppose i will look at it again for java. thanks for your suggestion.

Similar Threads

  1. Reading & Writing Binary files
    By chris3113 in forum VB Classic
    Replies: 2
    Last Post: 08-28-2005, 08:00 AM
  2. Replies: 7
    Last Post: 06-23-2005, 11:39 PM
  3. Replies: 0
    Last Post: 05-24-2005, 02:36 PM
  4. reading and writing a file
    By rzions in forum Web
    Replies: 0
    Last Post: 02-08-2001, 01:49 PM
  5. Replies: 1
    Last Post: 05-08-2000, 12:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center