0% found this document useful (0 votes)
157 views

Group C Assign 23

The document discusses storing binary numbers using doubly linked lists and functions for computing 1's and 2's complement and adding two binary numbers. It explains the node structure for a doubly linked list and the algorithms for finding the 1's and 2's complement of a binary number and adding two binary numbers using basic binary addition rules. The document also provides sample decimal to binary conversions and binary number operations.

Uploaded by

Siddhesh Mhatre
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)
157 views

Group C Assign 23

The document discusses storing binary numbers using doubly linked lists and functions for computing 1's and 2's complement and adding two binary numbers. It explains the node structure for a doubly linked list and the algorithms for finding the 1's and 2's complement of a binary number and adding two binary numbers using basic binary addition rules. The document also provides sample decimal to binary conversions and binary number operations.

Uploaded by

Siddhesh Mhatre
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
You are on page 1/ 4

Group C Roll No:

Assignment No: 9 Date:

Title:
Write C++ program for storing binary number using doubly linked lists. Write
functions
a) to compute 1‘s and 2‘s complement
b) add two binary numbers

Marks: Sign:
Group B

Assignment no 3

Title: (write)
Write C++ program for storing binary number using doubly linked lists. Write functions
a) to compute 1‘s and 2‘s complement
b) add two binary numbers
Index terms: Binary Numbers, Doubly linked list

Theory:

 Doubly Linked list:

A Doubly Linked List (DLL) contains an extra pointer, typically called previous pointer,
together with next pointer and data which are there in singly linked list.

Node structure of DLL in C :

/* Node of a doubly linked list */


struct node
{
   int data;
   struct node *next; // Pointer to next node in DLL
   struct node *prev; // Pointer to previous node in DLL 
};

 1’s and 2’s complement of a Binary Number

1’s complement of a binary number is another binary number obtained by toggling all bits in
it, i.e., transforming the 0 bit to 1 and the 1 bit to 0.

Examples:

1's complement of "0111" is "1000"


1's complement of "1100" is "0011"

2’s complement of a binary number is 1 added to the 1’s complement of the binary number.
Examples:

2's complement of "0111" is "1001"


2's complement of "1100" is "0100"
Algorithm:

1. Read decimal value from user.


2. Convert it into binary format.
3. Store all digits in Doubly linked list.
4. Finds the 1's complement of the binary number

for(i=0; i<SIZE; i++)


{
if(binary[i]=='1')
{ onesComp[i] = '0';
} else if(binary[i]=='0')
{ onesComp[i] = '1';
}
}
onesComp[SIZE] = '\0';
5. Find 2’ s complement by adding one to 1's complement.
6. Print 1's complement and 2s complement.

 Addition of binary numbers:


Rules for binary addition:

Conclusion(write)

Questions(write)

1. Write a C/C++ program to convert decimal number to binary number.


2. Write a C/C++ program for multiplication of binary number.
3. Write advantages of DLL over singly linked list.
4. Write a C/C++ program for subtraction of binary number

You might also like