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.
-
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 considerationphuclv– phuclv2014-01-23 08:33:43 +00:00Commented Jan 23, 2014 at 8:33
Add a comment
|
1 Answer
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).
1 Comment
user1334254
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.