Binary stuff

Discussion in 'Scripting & Programming' started by zxspectrum, Oct 9, 2008.

  1. zxspectrum

    zxspectrum Terabyte Poster Forum Leader Gold Member

    2,092
    216
    244
    OK people does any one know what bit reversing and negating in the case of binary numbers are

    Bit reverse to me is having a number like 101010 and changing it to 010101

    and negating, im not sure

    Any help is always appreciated.

    Ed
     
    Certifications: BSc computing and information systems
    WIP: 70-680
  2. dmarsh
    Honorary Member 500 Likes Award

    dmarsh Petabyte Poster

    4,305
    503
    259
    Negating, get the ones complement by inverting every bit.

    Get the twos complement by adding one.

    E.g. 7 = 00000111

    ones complement = 11111000

    twos complement = 11111001

    11111001 = -7

    You've negated the number.

    Theres also operations like shift left/shift right or invert/logical NOT.

    Are you sure they meant reverse as in left to right or as in a logical bitwise NOT sense ?
     
  3. Mathematix

    Mathematix Megabyte Poster

    969
    35
    74
    Bit Negation

    This just involves flipping the ones and zeros in a binary sequence, eg:

    1011 becomes 0100
    1111 becomes 0000
    1001 becomes 0110

    etc.

    Looking into logic you will see that this employs the 'not gate' or 'inverter'. As described above this is the "one's complement negation".

    The "two's complement negation" has an entirely different use altogther in allowing for bit subtraction, where '1' is added to the one's complement initially. Let's go through an example:

    14 - 7 = 7

    14 = 1110
    7 = 0111

    One's complement -7 is 1000
    Two's complement -7 is (1000 + 0001) = 1001

    14 + (-7) = 1110 + 1001 = 0111

    There is a leading '1' which overflows (or more preferably is 'carried'). This is the reason for having two's complement.

    Bit reverse

    This is a bit of a tougher one to explain. It involves 'rotating bits' from say position x to position n - (x + 1), where n is the number of bit representing a value. Eg:

    0000 0010 - the '1' is in position 6.
    0100 0000 - the '1' is now in position 8 - (6 + 1) = 1

    Where the bit positions are numbered from 0 to n - 1.

    Bit reverse operations are normally calculated using 'bit shifts', but this is the easiest way to explain it. :)
     
    Certifications: BSc(Hons) Comp Sci, BCS Award of Merit
    WIP: Not doing certs. Computer geek.
  4. zxspectrum

    zxspectrum Terabyte Poster Forum Leader Gold Member

    2,092
    216
    244
    Cheers for your help guys

    Mat

    Where you say the 1 is in position6 and then after that the 1 is in position 1 how do you come to that conclusion

    The way i read it is this

    31 16 8 4 2 1 0
    0 0 0 0 0 1 0 0 im assuming base 2 here as its binary or am i looking at it totally wrong??

    Ed
     
    Certifications: BSc computing and information systems
    WIP: 70-680
  5. Mathematix

    Mathematix Megabyte Poster

    969
    35
    74
    Sorry, zx... forgot to explain the numbering...

    I'm numbering left to right from 0 to n - 1, so the '1' is placed at position 6. It has nothing to do with the powers of two, just the ordinal position. :)
     
    Certifications: BSc(Hons) Comp Sci, BCS Award of Merit
    WIP: Not doing certs. Computer geek.
  6. zxspectrum

    zxspectrum Terabyte Poster Forum Leader Gold Member

    2,092
    216
    244
    Dont know if im being thick here Mat but i still cant work how your getting to the numbers 6 and 8

    I see you have grouped them in to sets of 4 so 0000 0010 would be 2 and 0100 0000 would be 64 which is way off the mark yeah??? Are you putting them into something different , sorry to hassle you on this

    Ed
     
    Certifications: BSc computing and information systems
    WIP: 70-680
  7. Mathematix

    Mathematix Megabyte Poster

    969
    35
    74
    Okay, let me try this way.

    Pos 0-1-2-3-4-5-6-7 (there are 8 positions numbered 0 thru 7)
    Bit 0-0-0-0-0-0-1-0

    then 8 (positions) - (6 (the original place above) + 1) = 1 (the new position below).

    Pos 0-1-2-3-4-5-6-7
    Bit 0-1-0-0-0-0-0-0

    Got it? :biggrin
     
    Certifications: BSc(Hons) Comp Sci, BCS Award of Merit
    WIP: Not doing certs. Computer geek.
  8. zxspectrum

    zxspectrum Terabyte Poster Forum Leader Gold Member

    2,092
    216
    244
    Yeah i think so Mat

    You were using base 8 and id not clicked on to that

    Thanks for your help

    Ed
     
    Certifications: BSc computing and information systems
    WIP: 70-680
  9. Mathematix

    Mathematix Megabyte Poster

    969
    35
    74
    I'm not using 'base 8', I'm using a 'byte'! Be careful with terminology as 'base 8' is actually 'octal' - another numbering system. this has nothing to do with octal. :)
     
    Certifications: BSc(Hons) Comp Sci, BCS Award of Merit
    WIP: Not doing certs. Computer geek.

Share This Page

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.