Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. write only one bit to file

write only one bit to file

Scheduled Pinned Locked Moved C#
helptutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kiki99
    wrote on last edited by
    #1

    I don't know how to write to binary file only one bit and not one byte. Please help me! FileStream fs new FileStream("1.dat", FileMode.CreateNew); BinaryWriter w = new BinaryWriter(fs); w.Write(true); //write one byte w.Write(55); //write 4 bytes fs.Close(); Thanks

    D Y 2 Replies Last reply
    0
    • K Kiki99

      I don't know how to write to binary file only one bit and not one byte. Please help me! FileStream fs new FileStream("1.dat", FileMode.CreateNew); BinaryWriter w = new BinaryWriter(fs); w.Write(true); //write one byte w.Write(55); //write 4 bytes fs.Close(); Thanks

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      The smallest unit you can write to a file is 1 byte. Even though you're writing a single bit to a file, any file operation you try and use will only write a single byte to store your bit in. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

      1 Reply Last reply
      0
      • K Kiki99

        I don't know how to write to binary file only one bit and not one byte. Please help me! FileStream fs new FileStream("1.dat", FileMode.CreateNew); BinaryWriter w = new BinaryWriter(fs); w.Write(true); //write one byte w.Write(55); //write 4 bytes fs.Close(); Thanks

        Y Offline
        Y Offline
        yoaz
        wrote on last edited by
        #3

        the overloaded BinaryWriter.Write() method does not support anything smaller than a byte, which is the smallest natural unit. Note that the bool type is not a bit long. You can try using a BitArray, but i'm not sure this will help, and it's not very efficient. there are no facts, only interpretations

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups