<< Chapter < Page Chapter >> Page >

Unsigned integers

Unsigned integers are represented by a fixed number of bits (typically 8, 16, 32, and/or 64)

  • With 8 bits, 0…255 (0016…FF16) can be represented;
  • With 16 bits, 0…65535 (000016…FFFF16) can be represented;
  • In general, an unsigned integer containing n bits can have a value between 0 and 2 n 1 MathType@MTEF@5@5@+=feaagaart1ev2aaatCvAUfeBSjuyZL2yd9gzLbvyNv2CaerbuLwBLnhiov2DGi1BTfMBaeXatLxBI9gBaerbd9wDYLwzYbItLDharqqtubsr4rNCHbGeaGqiVCI8FfYJH8YrFfeuY=Hhbbf9v8qqaqFr0xc9pk0xbba9q8WqFfeaY=biLkVcLq=JHqpepeea0=as0Fb9pgeaYRXxe9vr0=vr0=vqpWqaaeaabiGaciaacaqabeaadaqaaqaaaOqaaiaaikdadaahaaWcbeqaaiaad6gaaaGccqGHsislcaaIXaaaaa@3970@

If an operation on bytes has a result outside this range, it will cause an ‘overflow’

Signed integers

The binary representation discussed above is a standard code for storing unsigned integer numbers. However, most computer applications use signed integers as well; i.e. the integers that may be either positive or negative.

In binary we can use one bit within a representation (usually the most significant or leading bit) to indicate either positive (0) or negative (1), and store the unsigned binary representation of the magnitude in the remaining bits.

However, for reasons of ease of design of circuits to do arithmetic on signed binary numbers (e.g. addition and subtraction), a more common representation scheme is used called two's complement. In this scheme, positive numbers are represented in binary, the same as for unsigned numbers. On the other hand, a negative number is represented by taking the binary representation of the magnitude:

  • Complement the bits : Replace all the 1's with 0's, and all the 0's with 1's;
  • Add one to the complemented number.

Example

+4210 = 001010102 and so-4210 = 110101102
  • Binary number with leading 0 is positive
  • Binary number with leading 1 is negative

Example

Performing two's complement on the decimal 42 to get -42

Using a eight-bit representation

42= 00101010 Convert to binary 11010101 Complement the bits11010101 Add 1 to the complement + 00000001-------- 11010110 Result is -42 in two's complement

Arithmetic operations on integers

Addition and subtraction of integers

Addition and subtraction of unsigned binary numbers

Binary Addition is much like normal everyday (decimal) addition, except that it carries on a value 2 instead of value 10.

0 + 0 = 0

0 + 1 = 1

1 + 0 = 1

1 + 1 = 0, and carry 1 to the next more significant bit

Example

00011010 + 00001100 = 00100110 1 1 carries0 0 0 1 1 0 1 0 = 26(base 10) + 0 0 0 0 1 1 0 0 = 12(base 10)---------------- 0 0 1 0 0 1 1 0 = 38(base 10)11010001 + 00111110 = 100011010 1 1 1 carries1 1 0 1 0 0 0 1 = 208 (base 10) + 0 1 0 0 1 0 0 1 = 73 (base 10)---------------- 1 0 0 0 1 1 0 1 0 = 281 (base 10)

The result exceeds the magnitude which can be represented with 8 bits. This is an overflow .

Subtraction is executed by using two's complement

Addition and subtraction of signed binary numbers

Multiplication and division of integers

Binary Multiplication

Multiplication in the binary system works the same way as in the decimal system:

0 x 0 = 0

0 x 1 = 0

1 x 0 = 0

1 x 1 = 1, and no carry or borrow bits

Example

00101001 × 00000110 = 11110110 0 0 1 0 1 0 0 1 = 41(base 10)× 0 0 0 0 0 1 1 0 = 6(base 10) ----------------------0 0 0 0 0 0 0 0 1 0 1 0 0 10 1 0 1 0 0 1 ----------------------------0 0 1 1 1 1 0 1 1 0 = 246(base 10) 00010111 × 00000011 = 010001010 0 0 1 0 1 1 1 = 23(base 10)× 0 0 0 0 0 0 1 1 = 3(base 10) ----------------------1 1 1 1 1 carries 0 0 1 0 1 1 10 0 1 0 1 1 1 0 0 1 0 0 0 1 0 1 = 69(base 10)

Questions & Answers

what does preconceived mean
sammie Reply
physiological Psychology
Nwosu Reply
How can I develope my cognitive domain
Amanyire Reply
why is communication effective
Dakolo Reply
Communication is effective because it allows individuals to share ideas, thoughts, and information with others.
effective communication can lead to improved outcomes in various settings, including personal relationships, business environments, and educational settings. By communicating effectively, individuals can negotiate effectively, solve problems collaboratively, and work towards common goals.
it starts up serve and return practice/assessments.it helps find voice talking therapy also assessments through relaxed conversation.
miss
Every time someone flushes a toilet in the apartment building, the person begins to jumb back automatically after hearing the flush, before the water temperature changes. Identify the types of learning, if it is classical conditioning identify the NS, UCS, CS and CR. If it is operant conditioning, identify the type of consequence positive reinforcement, negative reinforcement or punishment
Wekolamo Reply
please i need answer
Wekolamo
because it helps many people around the world to understand how to interact with other people and understand them well, for example at work (job).
Manix Reply
Agreed 👍 There are many parts of our brains and behaviors, we really need to get to know. Blessings for everyone and happy Sunday!
ARC
A child is a member of community not society elucidate ?
JESSY Reply
Isn't practices worldwide, be it psychology, be it science. isn't much just a false belief of control over something the mind cannot truly comprehend?
Simon Reply
compare and contrast skinner's perspective on personality development on freud
namakula Reply
Skinner skipped the whole unconscious phenomenon and rather emphasized on classical conditioning
war
explain how nature and nurture affect the development and later the productivity of an individual.
Amesalu Reply
nature is an hereditary factor while nurture is an environmental factor which constitute an individual personality. so if an individual's parent has a deviant behavior and was also brought up in an deviant environment, observation of the behavior and the inborn trait we make the individual deviant.
Samuel
I am taking this course because I am hoping that I could somehow learn more about my chosen field of interest and due to the fact that being a PsyD really ignites my passion as an individual the more I hope to learn about developing and literally explore the complexity of my critical thinking skills
Zyryn Reply
good👍
Jonathan
and having a good philosophy of the world is like a sandwich and a peanut butter 👍
Jonathan
generally amnesi how long yrs memory loss
Kelu Reply
interpersonal relationships
Abdulfatai Reply
What would be the best educational aid(s) for gifted kids/savants?
Heidi Reply
treat them normal, if they want help then give them. that will make everyone happy
Saurabh
What are the treatment for autism?
Magret Reply
hello. autism is a umbrella term. autistic kids have different disorder overlapping. for example. a kid may show symptoms of ADHD and also learning disabilities. before treatment please make sure the kid doesn't have physical disabilities like hearing..vision..speech problem. sometimes these
Jharna
continue.. sometimes due to these physical problems..the diagnosis may be misdiagnosed. treatment for autism. well it depends on the severity. since autistic kids have problems in communicating and adopting to the environment.. it's best to expose the child in situations where the child
Jharna
child interact with other kids under doc supervision. play therapy. speech therapy. Engaging in different activities that activate most parts of the brain.. like drawing..painting. matching color board game. string and beads game. the more you interact with the child the more effective
Jharna
results you'll get.. please consult a therapist to know what suits best on your child. and last as a parent. I know sometimes it's overwhelming to guide a special kid. but trust the process and be strong and patient as a parent.
Jharna
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Introduction to computer science. OpenStax CNX. Jul 29, 2009 Download for free at http://cnx.org/content/col10776/1.1
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Introduction to computer science' conversation and receive update notifications?

Ask