working with bits in c#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • smitamone
    New Member
    • Feb 2010
    • 2

    #1

    working with bits in c#

    Hallo!

    I have to do the following tasks:

    1) I need to read first 8 bytes from file
    2) Get all 64 bits for editing
    3) Change some bits and save its back to file

    basically i want to compress astring of 8 characters to to 7 characters...

    my idea is to use MSB of every character(ascii representation ) which is always 0 to store bits from 8th character ...

    can u tell me how do i implement this?
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Danger Will Robinson! Danger!
    The first 0 is not always a 0.
    If your file is using Unicode type then it may or may not be a 0 since Unicode is two bytes per character. This is how you handle languages like Arabic or Japanese.

    If you do this with a simple English, straight text document there may not be any problem. But if you do it with some other language, you will more than likely get "unexpected results".

    Comment

    • smitamone
      New Member
      • Feb 2010
      • 2

      #3
      can u give me a example code and explain?

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        No. I'm not writing your code for you. Take the time to do a little research. Go read up on Unicode and you'll understand. http://unicode.org/

        As I said earlier, if you are only dealing with ASCII files, you'll be fine doing as you describe. If you want to deal with other languages that use 2-byte characters *THAT'S* when you run into trouble.

        Comment

        Working...