Amazon.com Widgets Chapter 10 - sign extension - page 222
Welcome, Guest. Please login or register.
Did you miss your activation email?
November 23, 2014, 10:01:45 AM
Home Help Search chat Login Register 
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+ Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+ Old Stuff
| |-+ Chapter Study
| | |-+ Chapter 10 - More on Variables and Data Types
| | | |-+ Chapter 10 - sign extension - page 222
Pages: [1] Go Down
Print
Author Topic: Chapter 10 - sign extension - page 222 (Read 1803 times)
enigmakv
Newbie
*
Posts: 37







on: September 23, 2009, 08:25:17 PM

I know it is a fairly minor topic, but can someone explain the following sentence to me?

Quote
For example, on a Mac, the character constant '\377' is converted to the value -1 because its value is negative when treated as a signed 8-bit quantity.

I can't for the life of me make sense of that statement.  What is '\377'?  What is it when treated as an 8-bit quantity? etc...

Thanks,

Kevin
Logged
rgronlie
Global Moderator
Full Member
*****
Posts: 212







Reply #1 on: September 24, 2009, 01:11:41 AM

\377 is octal ( base 8 )

converting to decimal ( base 10 ):

3*8^2 + 7*8^1 + 7*8^0 = 255 (unsigned) or -1 (signed)

unsigned 8-bit values have a range of 0 to 255

signed 8-bit values have a range of -128 to 127
Logged

Sanity: Minds are like parachutes. Just because you've lost yours doesn't mean you can borrow mine.
enigmakv
Newbie
*
Posts: 37







Reply #2 on: September 24, 2009, 11:10:33 PM

\377 is octal ( base 8 )

converting to decimal ( base 10 ):

3*8^2 + 7*8^1 + 7*8^0 = 255 (unsigned) or -1 (signed)

unsigned 8-bit values have a range of 0 to 255

signed 8-bit values have a range of -128 to 127


OK, I understand the octal to decimal conversion to get 255, but how does that become -1 if it is signed?
Logged
rgronlie
Global Moderator
Full Member
*****
Posts: 212







Reply #3 on: September 25, 2009, 01:40:25 AM

I'll refer you to the great Wiki Smiley It gives a better indepth description than I can.

Two's complement

Ryan
Logged

Sanity: Minds are like parachutes. Just because you've lost yours doesn't mean you can borrow mine.
Keeftausa
Newbie
*
Posts: 1

163137542 hedon.chyna.1050@gmail.com




Reply #4 on: April 02, 2011, 04:16:26 AM

But yes, you are correct, that should be O = 1  0.2 - at least we know youre paying attention

-ron
Logged
Pages: [1] Go Up
Print
Jump to:



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.