Bit Manipulation Questions

This is a discussion on Bit Manipulation Questions within the C++ Programming forums, part of the General Programming Boards category; Hello everyone, i've been reading many tutorials on bit manipulation and advanced bit manipulation. As seeing im new these may ...

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    3

    Bit Manipulation Questions

    Hello everyone, i've been reading many tutorials on bit manipulation and advanced bit manipulation. As seeing im new these may seem like funny questions but have in mind I am serious.

    When working with the bit wise operators (^, |, &, ~) what are you exactly doing? Comparing the two bytes or individual bits and if so for what purpose. I have seen this done for encryption programs exspecially using the exclusive or because it automatically flips every bit around, but in that case do certain bit patterns represent certain characters or (I do know integers of course, its binary). I have seen that many decryption programs use direct bit manipulation to find encapsulated data and there it is again, are certain characters programmed represented by certain digits? say 0001 = a? Im still pretty much a poor sappy newbie but help is appreciated =D. Also much explanation one what bits are used for today helps and how it relates to data.

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    Bits are used to send more than one piece of data in a variable. Say you have the number:

    10111

    The first bit might signify colored background, the second bit might signify minimized or maximized, the third bit might be scroll bars, etc., with 1 signifying yes, and 0 no. Bitwise manipulators are used to perform operations on the bits: find out what the bits are at certain positions, switch them from yes to no and vice versa, etc.

    My advice: new people should skip bitwise manipulaters. Nothing you will study about C++ from here on out will ever rely on knowing bitwise manipulators.
    Last edited by 7stud; 08-11-2003 at 08:38 PM.

  3. #3
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    >> Nothing you will study about C++ from here on out will ever rely on knowing bitwise manipulators.


    i think that statement might be a little extreme. For example, extendable bitwise hashing is a very popular method of hashing. encryption, as mentioned above, also makes good use of bitwise operators. You are right about newbie study though, bitwise operators are more than you need at first.

  4. #4
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    Sorry, I should have said in beginning to intermediate C++.

  5. #5
    Registered User
    Join Date
    Aug 2003
    Posts
    3
    Thank you very much =D.

  6. #6
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    Hardware, Firmware, Embedded Systems.

    All data inside the computer is in binary format. Most of the time, the compiler and operating system take care of the conversion, so neither the programmer or user really cares about that. I was amazed when I discovered that there is no binary "built-into" C, or C++.

    I mostly work with hardware... I use binary in my test programs for troubleshooting the hardware. A single bit might indicate the state of a switch, or a single bit might turn-on an LED. You can use an oscilloscope to see the high/low (1 or 0) state of a port. (The data on the data bus is always changing, so the 'scope won't tell you anything, unless the signal is stuck high or low.)

    Programmers who write "firmware"* for embedded systems, or who write drivers, often deal in binary. Bytes and single-bits in a "register"* often indicate the status of something, or come configuration setting.

    All of this bitwise programming is done using hexadecimal, because it is easy (for us humans) to convert between hex and binary.

    *FIRMWARE: Software that is semi-permanently stored in an EPROM or flash.

    *REGISTER: One or more bytes of fixed-address memory, reserved for a particular use, often located physically on a daughter-card, in a peripheral device, or inside a microprocessor. Not part of the regular RAM... Not part of the heap.
    Last edited by DougDbug; 08-12-2003 at 12:51 PM.

  7. #7
    Registered User
    Join Date
    Aug 2003
    Posts
    3
    Yes I read some articles on Diodes and LED's as well as Boolean Gates. Most of which used bits to represent data or as you said "switch on an LED". So on a physical level what is a bit? An electrical current moved around to a final destination, routed through boolean gates? I really also wanted to know what "memory" is on a physical level. Since computers were built up physically untill we reached the point of virtual memory. Im kind of an amatuer (only 15 -=( ) so my knowledge is a bit limited =D. Thank you all for your help though, and 7Stud sorry for posting on another forum with the same question, no one at CPP-Home.com was responding at the time.

    ::Edit:: - By the way, Perspective nice avatar. Looks really nice when your overtired and its 3:00 A.M. ~_^

  8. #8
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    Physical Memory...

    what "memory" is on a physical level.
    Hmmm...
    Well, computers still have physical memory. Virtual memory means that if I read the byte or word at... say address 1000, maybe I'm really reading from address 2000, or from the hard disk. If you write to some address via a pointer, the virtual memory might move the data to make room for another program or something... But the operating system can still find it by re-directing the pointer. Confusing Eh?

    When you studied gates, you probably studied flip-flops (I hope). A flip-flop can hold it's state, so if you add some more circuitry to test (read) its state, you have a one-bit memory.

    A ROM (or EPROM) chip might have 8 address lines (pins) and 8 data lines. Inside it has a bunch of "latches" (like flip-flops). When you put some bit-pattern on the address lines, (and turn-on the enable line)... the data stored at that address will appear on the data lines. If you hold the address/enable lines instead of changing them at MHz and GHz rates, you can read the data with a 'scope or meter. If address zero contains 55 Hex, and you put 0000 0000 on the address lines, you will find 0101 0101 (=55 hex) on the address lines. Put 0000 0001 on the address lines, and whatever data is stored at address 1 will appear on the data lines.

    You can't check a bit inside memory with a 'scope or meter, you have to get it on the bus. And, you can't statically read/write RAM or ROM like I described while the processor is running.... But you can put it into a loop and read/write to the same address over and over. (That get's tricky too 'cause it also has to read the instructions telling it to loop.)

    You can find more info about memory (and lots of other technical stuff) at ePanarama.net

    If you need clarification, or have any more questions for me, send me a PM (Private Message) 'cause we're getting off the C++ topic for this board.
    Last edited by DougDbug; 08-12-2003 at 02:32 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about Bit Manipulation.
    By parastar in forum C Programming
    Replies: 5
    Last Post: 01-28-2009, 07:46 AM
  2. Bit manipulation
    By Neo1 in forum C++ Programming
    Replies: 8
    Last Post: 03-24-2008, 11:53 AM
  3. A Question About Unit Testing
    By Tonto in forum C++ Programming
    Replies: 2
    Last Post: 12-14-2006, 07:22 PM
  4. quick question about bit manipulation
    By PJYelton in forum C++ Programming
    Replies: 7
    Last Post: 01-10-2003, 12:18 AM
  5. 2 questions about file manipulation
    By Music_Man in forum C Programming
    Replies: 3
    Last Post: 12-02-2001, 05:09 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21