3

What is the best or recommended method for bit shifting a large amount of binary data in C? I have a 200K binary file and I want to left, then right shift the entire lot.

一二三
  • 21,059
  • 11
  • 65
  • 74
  • How far left & right are you wanting to shift it ? and are you wanting to preserve data or are you willing to lose it (and keep the same size file) ? – NWS Nov 29 '11 at 11:16
  • What's "shifting a file" supposed to do? From your description it sounds that you only need to shift a little inside some kind of loop. Please provide more details. – Jon Nov 29 '11 at 11:19
  • Want to preserve the data on the shift back. Should be identical as before I performed the shifting. –  Nov 29 '11 at 11:20
  • I think @Jon is right, just loop through your file & create a new one in the process. Dont forget to check for loss of data at word boundaries. (or however large a data item you can shift on!) – NWS Nov 29 '11 at 11:28
  • @Jon: It's a study in shifting a very large number. Looking for the best or known techniques. Thought about putting the data into a char* then looping across that while performing bitwise, but I suspect I need to convert those "string" characters into their decimal equivalent then perform the operations one number at a time. –  Nov 29 '11 at 11:28
  • Joe: Well, right now a binary (or decimal) number that is 200k long. –  Nov 29 '11 at 11:37

1 Answers1

0

If your OS can support it use a memory mapped file. Then do a bit shift It'll be very very efficient.

See this answer for more info: What are the advantages of memory-mapped files?

Community
  • 1
  • 1
Preet Sangha
  • 64,563
  • 18
  • 145
  • 216