Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Java Program To Find Decimal Equivalent Of Binary Linked List

  • Last Updated : 03 Jan, 2022

Given a singly linked list of 0s and 1s find its decimal equivalent.

Input: 0->0->0->1->1->0->0->1->0
Output: 50   

Input: 1->0->0
Output: 4

The decimal value of an empty linked list is considered as 0.

Initialize the result as 0. Traverse the linked list and for each node, multiply the result by 2 and add the node’s data to it.


// Java Program to find decimal value 
// of binary linked list 
class GFG{
// Link list Node 
static class Node 
    boolean data; 
    Node next; 
// Returns decimal value of binary 
// linked list
static int decimalValue(Node head) 
    // Initialized result 
    int res = 0
    // Traverse linked list 
    while (head != null
        // Multiply result by 2 and 
        // add head's data 
        res = (res << 1) + (; 
        // Move next 
        head =; 
    return res; 
// Utility function to create a 
// new node. 
static Node newNode(int data) 
    Node temp = new Node(); = (data == 1
                 true : false); = null
    return temp; 
// Driver code
public static void main(String args[])
    // Start with the empty list 
    Node head = newNode(1); = newNode(0); = newNode(1); = newNode(1); 
    System.out.print("Decimal value is "
// This code is contributed by Arnab Kundu

Output : 

Decimal value is 11

Please refer complete article on Decimal Equivalent of Binary Linked List for more details!

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!