COA Tutorial

Computer Organization and Architecture Tutorial Basic Terminologies Related to COA Digital Number System Computer Organization and Architecture Data Formats Fixed and Floating-Point Number IEEE Standard 754 Floating Point Numbers Control Unit Organization Data Path, ALU and Control Unit Micro-Operations CPU Registers Addressing Modes COA: Interrupt and its types Instruction Cycle: Computer Organization and Architecture Instruction Pipelining and Pipeline Hazards Pipelining: Computer Organization and Architecture Machine Instructions 8085 instructions set 8085 Pin Configuration Addressing mode in 8085 microprocessor Advantages and Disadvantages of Flash Memory BCD to 7 Segment Decoder Biconnectivity in a Graph Bipartite Graph CarryLook Ahead Adder Control Signals in 8155 Microprocessor Convert a number from base 2 to base 6 Ethernet Frame Format Local Broadcast Address and loopback address Microprocessor classification Use Case Diagram for the online bank system 8086 Microprocessor Pin Configurations 8255 Microprocessor Operating Modes Flag Register of 8086 Microprocessor Data Transfer and Manipulation 8085 Arithmetic Instructions Assembly Language Register What is Cache Associativity? Auxiliary Memory in COA Associative Memory in Computer Architecture SCSI Bus in Computer Architecture What are Registers in Microprocessor What is Associative Memory 1 Persistent CSMA What is Floating-Point Representation in Computer Architecture? What is a Serial Port in a Computer? What is Cluster Computing What is Batch Processing in Computer Advantages of Client Server Architecture Spooling Meaning in Computer System Magnetic Core Memory Magnetic Ink Card Reader Decision Making Tools and Techniques Digital Electronics using Semiconductor Memory What is Internal Chip Organization in Computer Architecture? What is Hardwired Control Unit? Definition of Diodes in Electronics Advantages of FSK Web Server Architecture How the OS interfaces between the user, apps, hardware? Discuss the I/O Interface in Computer Architecture Difference between Internal Fragmentation and External Fragmentation MDR in Computer Architecture

Convert a number from base 2 to base 6

Base 2

Base 2 is the format where you can represent any number with just two values which are 0 and 1. With the help of 0s and 1s, we can represent any number we want. It is also called Binary format.

Base6

Base 6 is the format where we can use 6 digits (0 to 5) to represent any number. Base 6 is generally not used, while base 2 (binary) is used in computers and complete electronics.

In real life, we deal with the base 10 format, which is also called decimal format, where to represent any number; we use 10 digits (0 to 9).

To convert any number from base 2 to base 6, we will follow the following steps:

1. Convert the number into base 10 (decimal) from base 2(binary)

2. Now convert the number from base 10 to base 6.

For example:

We have a base 2 number N=(1100101)2, and our task is to convert this N into base 6.

Step1: 

From LSB (Least Significant Bit), add each number, and it’s multiplied by 2 to the power of its index.

          N In decimal would be: (1X26)+(1X25)+(0X24)+(0X23)+(1X22)+(0X21)+(1X20)

          So N = (101)10

Step2:

Now convert this 101 into an equivalent base 6 number by the dividing method.

          ans=0

          101%6=5 so add 5 into ans in LSB ,Now ans= 5

          Value => 101/6=16

          Now 16%6=4 so ad d4 into ans in LSB, Now ans=45

          value=>   16/6=2

          Since the value is lesser than 5, just add into ans in lSB and stop so ans=245

So finally, our base 6 would be = (245).

We will see the JAVA code for the following conversion:

Java Code:

class HelloWorld {
    public static void main(String[] args) {
       System.out.println(base10Tobase6(base2Tobase10("1100101")));
    }
    public static int base2Tobase10(String binary){
        
        int n=binary.length();
        int ans=0;
        for(int i=0;i<n;i++){
            char ch=binary.charAt(i);
            if(ch=='1')
            ans+=Math.pow(2,n-i-1);
        }
        return ans;
    }
    
    public static String base10Tobase6(int decimal){
        int ans=0;
        int idx=0;
        while(decimal>0){
            ans+=(decimal%6)*Math.pow(6,idx++);
            decimal/=6;
        }
        return ans+"";
    }
}


If we discuss the time complexity and space complexity, then we will notice that the first function, which converts the N length string of binary numbers into an equivalent decimal number, has a time complexity of O(N). and the second function, which converts the decimal integer to base 6 string, has the time complexity of O(M), where M is the length of the bits in base 6 format. For any number, N will always be greater than and equal to M.

So finally, time complexity would be: O(N).

Space taken by the first function is O(1), as it takes only one integer variable to return its answer. The second function takes the O(M) space of the string to store the result of the base 6 format.

So space complexity would be: O(M).

We can reverse the above steps to convert the number from base 2 to base 6.

Step1: convert from base 6 to base 10

Step2: convert from base 10 to base 2

Example: 245 we can convert it into decimal which will be

          2X62+4X61+5X60, so the decimal equivalent will be equal to 101.

Step2 is to convert 101 to binary using the divide method by 2.

          value=101 ans=””.

          ans=(101)%2 ans value=101/2 so value=50 and ans=1

          ans=50%2 in MSB and value = 50/2 , so value=25 and ans=01

          ans=25%2 in MSB and value = 25/2 , so value=12 and ans=101

          ans=12%2 in MSB and value = 12/2 , so value=6 and ans=0101

          ans=6%2 in MSB and value = 6/2 , so value=3 and ans=00101

          ans=3%2 in MSB and value = 3/2 , so value=1 and ans=100101

ans=1%2 in MSB and value = 1/2 , so value=0 and ans=1100101

As the value becomes 0 so, we will stop, and 1100101 is binary equivalent to 245 of base 6.

Java Code:

class HelloWorld {
    public static void main(String[] args) {
       System.out.println(base10Tobase2(base6Tobase10("245")));
    }
    public static int base6Tobase10(String base6){
        
        int n=base6.length();
        int ans=0;
        for(int i=0;i<n;i++){
            char ch=base6.charAt(i);
            ans+=(ch-'0')*Math.pow(6,n-i-1);
        }
        return ans;
    }
    
    public static String base10Tobase2(int decimal){
        String ans="";
        while(decimal>0){
            ans=(decimal%2)+ans;
            decimal/=2;
        }
        return ans;
    }
}

If we discuss the time complexity and space complexity, then we will notice that the first function, which converts the N length string of base 6 numbers into an equivalent decimal number, has a time complexity of O(M). The second function, which converts the decimal integer to a base 2 string, has the time complexity of O(N), where M is the length of the bits in base 6 format. For any number, N will always be greater than and equal to M.

So finally, time complexity would be: O(N).

Space taken by the first function is O(1), as it takes only one integer variable to return its answer. The second function takes the O(N) space of the string to store the result of the base 2 format.

So space complexity would be: O(N).