0

I need to read 256 bit for each step until binary file ends.Is there any operation in c to read bit by bit? I use fread function and read 32 chars. For all chars i shift bit by bit for 8 times. After reading ı write this 256 bits to a file. Do ı have to same thing to write? I mean do ı write 32 chars => 32*8 = 256 bit.

1
  • you can write byte-by-byte. But disk drives are the slowest in computers so you'll want to write a bunch at once to speed up. Small files often aren't a problem but when you're writing a large amount of data then this should be taken into consideration Commented Jan 23, 2014 at 8:33

1 Answer 1

3

No, the minimum item you can read or write is a char (and keep in mind that's not necessarily 8 bits, it depends on the implementation). If you want to manipulate parts of a char once you have it in memory, you'll need to use the bitwise operators sich as &, | << and >> (and, or and left/right shift).

And yes, you can do fwrite to write an arbitrary number of characters (in the same manner as you use fread to read them).

Sign up to request clarification or add additional context in comments.

1 Comment

I have one more question :D I have a 32 char array so it is 256 bits. I need to rotate the left. IF it is 000111 it should be 001110. How can ı do that? Because ı don't have the bits, ı just have char array.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.