0% found this document useful (0 votes)
10 views13 pages

Dijkstra's Algorithm and Binary Storage

The document explains Dijkstra's algorithm for finding the shortest path between nodes, followed by a detailed process of converting binary numbers into normalized form, including steps for mantissa and exponent storage. It illustrates the consequences of precision loss due to fixed-length mantissa and exponent in binary representation. Additionally, it provides examples of converting decimal numbers to binary and storing them in a specified format using two's complement.

Uploaded by

eqaniqbal
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views13 pages

Dijkstra's Algorithm and Binary Storage

The document explains Dijkstra's algorithm for finding the shortest path between nodes, followed by a detailed process of converting binary numbers into normalized form, including steps for mantissa and exponent storage. It illustrates the consequences of precision loss due to fixed-length mantissa and exponent in binary representation. Additionally, it provides examples of converting decimal numbers to binary and storing them in a specified format using two's complement.

Uploaded by

eqaniqbal
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Dijkstra’s Algorithm

Working
Base → Town3 = 2

Base → Town3 → Town1 = 3

Base → Town3 → Town5 = 3

Base → Town2 = 5

Base → Town3 → Town5 → Town4 = 9

Base → Town3 → Town5 → Town6 = 8

—-------------------------------------------------------------------------------------------------------------
-----------

Given number
1011100.011001

This is simply a binary number with a binary point.

Step 1: Move the binary point (normalisation)


To normalise, move the binary point to the left until the number looks like:

0.1xxxxxxx × 2^something

Original number:

1011100.011001

Move the point 7 places to the left:

0.1011100011001 × 2⁷

This is now in normalised form.

Step 2: Mantissa (12 bits)


The mantissa must be 12 bits long (including the bits after the point).

From:

0.1011100011001

Keep only the first 12 bits:

0.101110001100

The remaining bits are discarded.


This causes loss of accuracy.

Step 3: Exponent (4 bits)


The binary point was moved 7 places, so the exponent is +7.

Binary representation of 7 using 4 bits:

0111

Since the exponent is positive, no two’s complement conversion is needed.

Final Answer (Part 1)


Part Stored Value

Mantissa 101110001100

Exponent 0111

Part 2: Consequence of storing the number


What happened?

Some bits of the original number were lost.

Why?

● The mantissa is limited to 12 bits


● The original number contains more bits

● Extra bits are discarded during storage

Consequence and justification


Consequence:
Loss of precision.

Justification:
The mantissa has a fixed length of 12 bits, so not all bits of the original binary number can b
e stored. This results in truncation, meaning the stored value is only an approximation of the
original number.

----------------------------------------------------------------------------------------------------------------
-----------

Given
● Mantissa: 10 bits
● Exponent: 6 bits
● Two’s complement used for both mantissa and exponent
● Number to store: –7.25

Step 1: Convert 7.25 to binary


Whole part: 7

7₁₀ = 111₂

Fractional part: 0.25

Binary fractions:

● 0.5 = 2⁻¹
● 0.25 = 2⁻²

So:

0.25₁₀ = 0.01₂

Combine both parts


7.25₁₀ = 111.01₂

Step 2: Make the number negative


So the value is:

-111.01₂

Step 3: Normalise the binary number


Normalised form must be:

0.1xxxx × 2ⁿ

Move the binary point 3 places left:

-111.01₂ = -0.11101 × 2³

Step 4: Store the mantissa (10 bits)


Mantissa includes:

● sign bit
● binary point
● bits after the point

Positive mantissa:

0.111010000

(added zeros to make 10 bits)

Convert mantissa to two’s complement (because number is negative)

Positive:

0.111010000

Invert bits:
1.000101111

Add 1:

1.000110000

Stored mantissa:

1000110000

Step 5: Store the exponent (6 bits)


Exponent = +3

Binary of +3:

000011

(Number is positive, so two’s complement not required)

Final Answer

Component Value

Mantissa 1000110000

Exponent 000011

Given

Component Binary value

Mantissa 1011000111

Exponent 000111
Step 1: Check sign of mantissa

● Mantissa first bit = 1 → negative


● Convert to positive (two’s complement):

Original: 1011000111

Invert: 0100111000

Add 1: 0100111001

● Positive mantissa = 0100111001

Step 2: Reconstruct normalised binary number

● Normalised mantissa (with hidden 1): 1.011000111


● Since original mantissa is negative → -1.011000111

Step 3: Convert mantissa to decimal

1 × 2⁰ =1

0 × 2⁻¹ = 0.5

1 × 2⁻² = 0.25

1 × 2⁻³ = 0.125

0 × 2⁻⁴ = 0

0 × 2⁻⁵ = 0

0 × 2⁻⁶ = 0

1 × 2⁻⁷ = 0.0078125

1 × 2⁻⁸ = 0.00390625

1 × 2⁻⁹ = 0.001953125

Add all:

1 + 0.25 + 0.125 + 0.0078125 + 0.00390625 + 0.001953125 ≈ 1.387671875


● Include sign → -1.387671875

Step 4: Apply exponent

● Exponent = 000111 = 7 (positive)


● Multiply mantissa by 2^7 = 128

Decimal value = -1.387671875 × 128 ≈ -177.617

Step 5: Final Answer

Denary value ≈ -177.62

Given
Mantissa: 10 bits

Exponent: 6 bits

Two’s complement used for both mantissa and exponent

Binary number to store:

0.00000011010111

Step 1: Normalise the binary number


Normalised form must be:

0.1xxxx × 2ⁿ

Move the binary point to the right until the first 1 is after the point.

Original:

0.00000011010111

Move the point 6 places to the right:

0.11010111 × 2⁻⁶

Step 2: Store the mantissa (10 bits)


Mantissa includes:

Sign bit

Binary point

Bits after the point

Number is positive, so two’s complement not required.

Take the first 10 bits and pad with zeros if needed:

0.110101110

Stored mantissa (remove the point for storage):

0110101110
Step 3: Store the exponent (6 bits)
Exponent = –6

Binary of +6:

000110

Convert to two’s complement (6 bits):

Invert bits:

111001

Add 1:

111010 = -32 + 16 + 8 +2

Stored exponent:

111010

Final Answer
Component Stored Value
Mantissa 0110101110
Exponent 111010

Given
Mantissa: 10 bits

Exponent: 6 bits

Two’s complement used for both mantissa and exponent

Number to store: –25.3125

Step 1: Convert 25.3125 to binary

Whole part: 25
25₁₀ = 11001₂
32 16 8 4 2 1
0 1 1001

Fractional part: 0.3125


1 0.5 0.25 0.125 0.0625
0 0 1 0 1

Binary fractions:

0.25 = 2⁻²

0.0625 = 2⁻⁴

0.3125₁₀ = 0.0101₂

Combined binary number


25.3125₁₀ = 11001.0101₂

Step 2: Make the number negative


-11001.0101₂

Step 3: Normalise the binary number


Normalised form must be:

0.1xxxx × 2ⁿ

Move the binary point 5 places left:

-11001.0101₂ = -0.110010101 × 2⁵

Step 4: Store the mantissa (10 bits)


Mantissa bits (after the point):

0.110010101

Pad with zeros to make 10 bits:

0.1100101010
Remove the point for storage:

01100101010

Convert mantissa to two’s complement (number is negative)

Positive mantissa:

01100101010

Invert bits:

10011010101
+ 1
10011010110

Add 1:

10011010110

Stored mantissa:

10011010110

1001101010

(10 bits)

Step 5: Store the exponent (6 bits)


Exponent = +5

Binary of 5 (6 bits):

000101
Exponent is positive → no two’s complement needed

Final Answer
Component Stored Value
Mantissa 1001101010
Exponent 000101
Appointment
--------------------------------
DateSeen : DATE
PatientID : INTEGER
DoctorID : STRING
Treatments : STRING
Medications : STRING
--------------------------------
SetPatientID(PatientNumber : INTEGER)
SetDoctor(DoctorID : STRING)
SetDateSeen(NewDate : DATE)
SetTreatments(NewTreatments : STRING)
SetMedications(NewMedications : STRING)
--------------------------------
GetDateSeen()
GetPatientID()
GetDoctorID()
GetTreatments()
GetMedications()
B part:
Mantissa:
1011000111
-> 1.011000111
2^7 Exponent

10110001.11

128 64 32 16 8 4 2 1 . 0.5 0.25


2^9 2^8 2^6 2^5 2^4 2^3 2^2 2^0 2^-1 2^-2
1 0 1 1 0 0 0 1 . 1 1

-128 + 32+16+1. 0.5+0.25 = -78.25

You might also like