how can I change 10 bit data into 2 bit data

Posted on 2002-03-25
Last Modified: 2010-04-15
it means change a dec number into a bin number
Question by:OdinXp2000
LVL 12

Expert Comment

ID: 6895817
We're not allowed to answer homework questions, unfortunately, so I doubt you're going to get a reply to this one.
LVL 84

Expert Comment

ID: 6895905
What do you mean by change 10 bit data into 2 bit data?

Expert Comment

ID: 6896247
throw 8 bits away. But why?
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.


Expert Comment

ID: 6897792
keep the most significant 2 bits. This can be done for images, for example. Convert 256 to 16 color depth, just keep the top bits and its a rough way to do that...

Accepted Solution

Anders_Rasmussen earned 50 total points
ID: 6898958
Hello OdinXP2000

(There's some spacing in this posting, I hope it'll survive. Otherwise copy/paste and read it in notepad or something)

Homework or no homework assignment, it's a question of understanding different radix-systems. (i.e. decimal, hex, binary etc.) and that's pretty important to learn, no matter where. So please excuse this rather long post...

The way numbers usually work when we deal with the decimal system is the following:

** Decimal system **

We have ten symbols, digits, called 0-9 and any given number is made up as a sequence of these digits.

A (positive, whole) number, can be considered as a sequence of digits

 [ a_n, a_n-1, ... , a4,a3,a2,a1,a0 ]

Now, every digit in itself only ranges from 0 to 9 but what's important is -where- the digit is placed in the sequence. The -decimal- system assigns each digit a power of 10, where the actual value of the number can be computed as the sum of

   digits[i] * 10^i
               base of number system

where i runs from n downto 0.


 the number 14332 (d(ecimal))

has the digit sequence, n=4..0


We calculate the value by performing

 1 * 10^4 + 4 * 10^3 + 3 * 10^2 + 3 * 10^1 + 2 * 10^0
 ^      ^
 digit  exponent

 = 14332 d

** What's binary then? ***

The binary system is absolutely the same, except for the usage of powers of 2 instead of 10, and instead of digits 0-9  we only use 0-1, now simply called "bits" instead of digits.

So we just sum

   bits[i] * 2^i

from i = n downto 0


   1011001 b(inary)

   1 * 2^6 + 0*2^5 + 1*2^4 + 1*2^3 + 0*2^2 + 0*2^1 + 1*2^0

 = 89 d


So, that'll give you the possibility to make your computer program read and understand any given number in ANY radix, be it binary, hex or decimal.

* I know that! I need to convert a number the OTHER way **

The way you need to go about is using division and
modulus with the given power of the desired number-system.

Example: You need to write the number
  123 d

in binary.

First, you'd would retrieve the lowest power by dividing the number by 2, i.e. the base of the binary number system.

 123 div 2 = 61

and the modulus (the remainder of the division) would be

 123 mod 2 = 1

There. That's your (least significant) digit. We'll put it in the end of the sequence... 1---+
                           .......1        there :)

And now we proceed to handle the next bit by performing division again (this time with the quotient left by the last division)

 61 div 2 = 30, 61 mod 2 = 1
we get another digit       +-----+

go again...

 30 div 2 = 15, 30 mod 2 = 0

and so forth, until you have zero as quotient, where the algorithm stops to get the number

    1111011 b

--algorithm-- DEC->BIN ----

   n is given number

   digitlist = [0,0,0,...,0] (just some integer list)

   as long as n > 0
     divide n by 2 and store in "q", the remainder in "r"
     place "r" as a digit in the list index 0
     increase index by 1
     set n = q
   ] repeat loop


** Sidenode **

(Mathematically, it is not relevant how you perform divisions and such, but for a computer efficient routines can be written. Especially when dealing with binary numbers where division (by 2, 4, 8, etc.) can be replaced by BIT-SHIFTS. Don't bother for now.)

I hope this was of some help to you,
 Anders Rasmussen.

Expert Comment

ID: 6898984

#include <stdio.h>

void main () {
    char InputString[] = "1047";
    char OutputString[5];
    int Value;
    int Ret;

    /* Convert decimal string to internal format*/
    /* internaly its binary*/
    Ret = sscanf ( InputString, "%d", &Value);
    if ( Ret != 1 ) { exit -1; }

    /* Convery internal representation binary to binary string */


Author Comment

ID: 6908036
Thank all of you very much!

Featured Post

Manage your data center from practically anywhere

The KN8164V features HD resolution of 1920 x 1200, FIPS 140-2 with level 1 security standards and virtual media transmissions at twice the speed. Built for reliability, the KN series provides local console and remote over IP access, ensuring 24/7 availability to all servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at  To view more iPhone tutorials, visit This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question