Thread: Binary Conversion anyone?

  1. #1
    Stressed Student :(
    Join Date
    Feb 2008
    Location
    Berkeley, CA
    Posts
    73

    Binary Conversion anyone?

    Okay So I have this

    100000 10100 11000 1000 0000 0000 0000

    This section of the binary is assumed to be sign extended

    1000 0000 0000 0000

    so it turns to this

    0xFFFF8000

    why?!?

    and why is the value of that sign extended decimal number -2048?

    isn't it 2^15?

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    Quote Originally Posted by NoobieGecko View Post
    Okay So I have this

    100000 10100 11000 1000 0000 0000 0000

    This section of the binary is assumed to be sign extended

    1000 0000 0000 0000

    so it turns to this

    0xFFFF8000

    why?!?
    My guess is because you have either defined or cast that portion of the field as signed.

    Todd
    Mainframe assembler programmer by trade. C coder when I can.

  3. #3
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    603
    What type of variable are you assigning this binary conversion to? If you look at the limits.h file this may help you decide what type(size) to assign your binary converted value to in decimal.

  4. #4
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    What does the source code look like?

  5. #5
    Stressed Student :(
    Join Date
    Feb 2008
    Location
    Berkeley, CA
    Posts
    73
    oh i just wanted to know how sign extension works, it's actually a mips instruction

    loadbyte

    lb $24,-2048($20)

    my guess is that "load byte" has to have a sign extended immediate

    so 1000 0000 0000 0000 == 0xffff8000... i guess ~_~

    just studying for a midterm :O

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. binary decimal conversion
    By eerok in forum C Programming
    Replies: 2
    Last Post: 01-24-2006, 09:51 PM
  3. Header File Question(s)
    By AQWst in forum C++ Programming
    Replies: 10
    Last Post: 12-23-2004, 11:31 PM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM