top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Write a C logic that stores 3 numeric values ranges 0 to 9 digits into 10 bits....eg 999 to fit into 10 bits

+1 vote
380 views

Write a C logic that stores 3 numeric values ranges 0 to 9 digits into 10 bits....eg 999 to fit into 10 bits

posted Mar 2, 2016 by Yeshwanth

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
10 binary bits can contain 0-1023 so we can simply mod the number by 1000 convert into binary shift 3 bit and repeat the process...
can you elaborate...send code
Its same as BCD where u are converting 1 digit to four binary bits. The change would be 3 digits would be converted to 10 binary bits. I will send the code tomorrow.

1 Answer

0 votes

Try something like this (obviously it will hit the overflow so you need to consider the overflow)

long long int decimal_binary(long int n) 
{
    long long int rem, i=1, binary=0;

    while (n!=0)
    {
        rem=n%2;
        n/=2;
        binary+=rem*i;
        i*=10;
    }

    return binary;
}

unsigned long long convert(unsigned long long int a)
{
   if (a<1000)
   {
     return decimal_binary(a);
   }
   else
   {
        return ((convert(a/1000))<<10)+(convert(a%1000));
   }
}
answer Mar 3, 2016 by Salil Agrawal
Similar Questions
+4 votes

Can someone please write a C program to reverse "N" nodes of list. In the above question N= 3.
Program should be generic so it can work for any value assigned to N.

Input List => 1 2 3 4 5 6 7 8 9 10 11
Output List => 3 2 1 6 5 4 9 8 7 10 11
for N=3

Input List => 1 2 3 4 5 6 7 8 9 10 11
Output List => 4 3 2 1 8 7 6 5 9 10 11
for n=4

+2 votes

Input: 1223
1+3=2*2
that means if sum of 1st and last digit is equal to product of remaining 2 digits then print 1+3=2*2 else error msg.

0 votes

Write a C code for the logic -
input: string, strong
output: strng

...