<< 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

if three forces F1.f2 .f3 act at a point on a Cartesian plane in the daigram .....so if the question says write down the x and y components ..... I really don't understand
Syamthanda Reply
hey , can you please explain oxidation reaction & redox ?
Boitumelo Reply
hey , can you please explain oxidation reaction and redox ?
Boitumelo
for grade 12 or grade 11?
Sibulele
the value of V1 and V2
Tumelo Reply
advantages of electrons in a circuit
Rethabile Reply
we're do you find electromagnetism past papers
Ntombifuthi
what a normal force
Tholulwazi Reply
it is the force or component of the force that the surface exert on an object incontact with it and which acts perpendicular to the surface
Sihle
what is physics?
Petrus Reply
what is the half reaction of Potassium and chlorine
Anna Reply
how to calculate coefficient of static friction
Lisa Reply
how to calculate static friction
Lisa
How to calculate a current
Tumelo
how to calculate the magnitude of horizontal component of the applied force
Mogano
How to calculate force
Monambi
a structure of a thermocouple used to measure inner temperature
Anna Reply
a fixed gas of a mass is held at standard pressure temperature of 15 degrees Celsius .Calculate the temperature of the gas in Celsius if the pressure is changed to 2×10 to the power 4
Amahle Reply
How is energy being used in bonding?
Raymond Reply
what is acceleration
Syamthanda Reply
a rate of change in velocity of an object whith respect to time
Khuthadzo
how can we find the moment of torque of a circular object
Kidist
Acceleration is a rate of change in velocity.
Justice
t =r×f
Khuthadzo
how to calculate tension by substitution
Precious Reply
hi
Shongi
hi
Leago
use fnet method. how many obects are being calculated ?
Khuthadzo
khuthadzo hii
Hulisani
how to calculate acceleration and tension force
Lungile Reply
you use Fnet equals ma , newtoms second law formula
Masego
please help me with vectors in two dimensions
Mulaudzi Reply
how to calculate normal force
Mulaudzi
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