count := 27
The algorithm to convert from decimal to any other base is the same regardless of the base. Divide the decimal value by the base and take the remainder. This is the least significant digit. Repeatedly divide the result of the previous division by the base to get the next least significant digit, and so on until the result is zero. Converting from any non-decimal base to any other base is slightly more difficult because C++ only recognises decimal and hexadecimal values (which are obviously converted to and from binary for our convenience). However since we must use character arrays to represent all other bases, the simplest solution is to convert those strings to decimal and then convert to the required base using the previously mentioned algorithm. The following program provides 2 functions which allow relatively simple conversion from decimal to any base from 2 to 62, and back to decimal again. Note that Dec2Base() returns a null-terminated character array of the exact size required which can then be passed to Bin2Dec() to produce the original decimal value. Between these two functions you can convert from any base to any other base in the range 2 to 62. The test program output is shown at the bottom of the example. #include <iostream> // Convert to any base from 2 to 62 inclusive. const char MAXBASE = 62; // Note: Higher bases are possible, but we only have 61 symbols // to play with (0-9, A-Z and a-z). Bases 11 through 36 are not // case-sensitive (although we will use upper-case here), while // higher bases use upper-case for the digits 10 through 35 and // lower-case for the digits 36 through 61. // Note that negative values use the '-' symbol, even in binary. // Computers do not. Computers represent the value -1 as being // 10000000 in 8-bit binary (the most significant bit represents // the sign). The value -0 does not exist hence the least // significant bit is zero, not 1 as might be expected. However, // we humans can use the '-' symbol to differentiate positive // and negative decimal values, so there's no reason not to // follow this convention with all bases. // Convert the given signed decimal value to the given base and // return the buffer pointed to by the non-zero pointer to pointer. char * Dec2Base( int dec, char base, char ** buffer ) { // The pointer-to-pointer MUST be non-zero. if( !buffer ) return( 0 ); // Point to the actual buffer (may be NULL). char * p = *buffer; // Check validity. if( dec && base > 1 && base <= MAXBASE ) { // Some variables. unsigned int size = 1; int rem = dec; // Is the value signed? if( rem < 0 ) { // Increase the initial size to cater for sign. ++size; // Convert the value to a positive value. rem = dec *= -1; } // Release the buffer, if required. if( p ) free( p ); // Calculate the required buffer size. while( rem /= base ) ++size; // Allocate a null-terminated buffer and zero it. p = ( char * ) malloc( ++size ); memset( p, 0, size-- ); // Update the output parameter. if( *buffer != p ) *buffer = p; // Point to the null terminator. p += size; // Start with the least-significant first. while( dec ) { // Step back to the correct character. --p; // Determine the digit value (remainder of division). rem = dec % base; // Determine the symbol. if( rem < 10 ) *p = '0' + rem; else if( rem < 36 ) *p = 'A' + rem - 10; else *p = 'a' + rem - 36; // Prepare for next digit. dec /= base; } // Signed value? if( p != *buffer ) { --p; *p = '-'; } } // Return the buffer. return( *buffer = p ); } int Base2Dec( char * buffer, char base ) { // Initialise the return value. int decimal = 0; // The buffer MUST BE null-terminated! unsigned int size = strlen( buffer ); // Point to the null-terminator. char * p = buffer; p += size; // The least-significant column is always the units, // with position value 1. unsigned int posval = 1; // Repeat until we reach the most-significant digit. while( p != buffer ) { // Step back to the digit. --p; // Store the the digit's value unsigned int val = *p; // Is it a sign? if( val == '-' ) // Adjust the result. decimal *= -1; // Not a sign, must be a digit. else { // Convert the digit to a decimal value. if( val > 'a' ) { val -= 'a'; val += 36; } else if( val > 'A' ) { val -= 'A'; val += 10; } else val -= '0'; // Multiply by the position value. val *= posval; // Increment the result. decimal += val; // Calculate the next position value. posval *= base; } } // Success. return( decimal ); } // Test program. int main() { // The test value: int decimal = -54321; // Initialise a pointer. char * buffer = 0; // Compute all bases from 2 through MAXBASE. char base = 1; while( ++base <= MAXBASE ) printf( "%d in decimal is %s in base %u\n", decimal, Dec2Base( decimal, base, &buffer ), base ); // Convert from MAXBASE back to decimal: printf( "%s in base %d is %d in decimal\n", buffer, MAXBASE, Base2Dec( buffer, MAXBASE )); // Don't forget to release the buffer! if( buffer ) free( buffer ); // Success! return( 0 ); } Output: -54321 in decimal is -1101010000110001 in base 2 -54321 in decimal is -2202111220 in base 3 -54321 in decimal is -31100301 in base 4 -54321 in decimal is -3214241 in base 5 -54321 in decimal is -1055253 in base 6 -54321 in decimal is -314241 in base 7 -54321 in decimal is -152061 in base 8 -54321 in decimal is -82456 in base 9 -54321 in decimal is -54321 in base 10 -54321 in decimal is -378A3 in base 11 -54321 in decimal is -27529 in base 12 -54321 in decimal is -1B957 in base 13 -54321 in decimal is -15B21 in base 14 -54321 in decimal is -11166 in base 15 -54321 in decimal is -D431 in base 16 -54321 in decimal is -B0G6 in base 17 -54321 in decimal is -95BF in base 18 -54321 in decimal is -7H90 in base 19 -54321 in decimal is -6FG1 in base 20 -54321 in decimal is -5I3F in base 21 -54321 in decimal is -5253 in base 22 -54321 in decimal is -4AFI in base 23 -54321 in decimal is -3M79 in base 24 -54321 in decimal is -3BML in base 25 -54321 in decimal is -3297 in base 26 -54321 in decimal is -2KDO in base 27 -54321 in decimal is -2D81 in base 28 -54321 in decimal is -26H4 in base 29 -54321 in decimal is -20AL in base 30 -54321 in decimal is -1PG9 in base 31 -54321 in decimal is -1L1H in base 32 -54321 in decimal is -1GT3 in base 33 -54321 in decimal is -1CXN in base 34 -54321 in decimal is -19C1 in base 35 -54321 in decimal is -15WX in base 36 -54321 in decimal is -12P5 in base 37 -54321 in decimal is -bNJ in base 38 -54321 in decimal is -ZRX in base 39 -54321 in decimal is -Xc1 in base 40 -54321 in decimal is -WCb in base 41 -54321 in decimal is -UXF in base 42 -54321 in decimal is -TGC in base 43 -54321 in decimal is -S2P in base 44 -54321 in decimal is -Qb6 in base 45 -54321 in decimal is -PUf in base 46 -54321 in decimal is -ORa in base 47 -54321 in decimal is -NRX in base 48 -54321 in decimal is -MUT in base 49 -54321 in decimal is -LaL in base 50 -54321 in decimal is -Kj6 in base 51 -54321 in decimal is -K4X in base 52 -54321 in decimal is -JHn in base 53 -54321 in decimal is -IXp in base 54 -54321 in decimal is -Hqa in base 55 -54321 in decimal is -HI1 in base 56 -54321 in decimal is -Gf0 in base 57 -54321 in decimal is -G8X in base 58 -54321 in decimal is -FZf in base 59 -54321 in decimal is -F5L in base 60 -54321 in decimal is -EaV in base 61 -54321 in decimal is -E89 in base 62 -E89 in base 62 is -54321 in decimal
4+2+1A bit is a 1 or a 0A byte is typically 8 bits, in which case it can have a value between 0 and 255.There are 2 possible values for each digit and there are 8 digits. 28 is 256. Because 0 is also a number, 11111111 is equal to 255 (decimal) rather than 256.The first digit is 20, the second digit is 21, the third digit is 22, and so on. The 1 is a yes and the 0 is a no.20 = 121 = 222 = 423 = 824 = 1625 = 3226 = 6427 = 128So 10101101 would be:[1 x 27] + [0 x 26] + [1 × 25] + [0× 24] + [1 × 23] + [1 × 22] + [0 × 21] + [1 × 20] =[1 x 128] + [0 x 64] + [1 × 32] + [0× 16] + [1 × 8] + [1 × 4] + [0 × 2] + [1 × 1] =128 + 32 + 8 + 4 + 1 = 173So, 10101101 = 173A more specific answer to you question:00000111[0 x 27] + [0 x 26] + [0 × 25] + [0× 24] + [0 × 23] + [1 × 22] + [1 × 21] + [1 × 20] =[0 x 128] + [0 x 64] + [0 × 32] + [0× 16] + [0 × 8] + [1 × 4] + [1 × 2] + [1 × 1] =4 + 2 + 1 = 7So, 00000111 = 7
17
A decimal number is built in binary from right to left, using the symbols 1 and 0 to represent powers of 2 . It starts with 20 and goes on until the decimal number has been reached in the form of 2n + ...... + 20. Although the number is built from right to left, starting with the lowest 20, the actual conversion starts from left to right with the highest power of 2 that can go into your number. step 1: Start with the highest power of 2 that goes into your number and subtract it, and put a 1 in the placeholder for its power. step 2: See if the next power of 2 down goes into your number step 3: If it goes in, subtract it from the remaining decimal number and put a 1 in it's power placeholder. If it doesn't go in, don't subtract, put a zero in its placeholder and move on to the next power. step 4: Repeat steps 2 and 3 until you arrive at 20 step5: Build your binary number from the powers of 2 placeholders, starting with the highest and ending with the lowest. Let's start with an example decimal number 750. 210 = 1024 is too much, so start with the next power. 29 = 512 can be subtracted from 750, leaving 238; put a 1 in its place. 28 = 256 can't be subtracted from 238; put a 0 in its place. 27 = 128 can be subtracted from 238, leaving 110; put a 1 in its place. 26 = 64 can be subtracted from 110, leaving 46; put a 1 in its place. 25 = 32 can be subtracted from 46, leaving 14; put a 1 in its place. 24 = 16 can't be subtracted from 14; put a 0 in its place. 23 = 8 can be subtracted from 14 leaving 6; put a 1 in its place. 22 = 4 can be subtracted from 6, leaving 2; put a 1 in its place. 21 = 2 can be subtracted from 2, leaving 0; put a 1 in its place. 20 = 1 can't be subtracted from 0; put a 0 in its place This builds the binary number: 1011101110 Which I'm guessing still looks foreign to you, but remember it it represents powers of 2. 29 + 0(28) + 27 + 26 + 25 + 0(24) + 23 + 22 + 21 + 0(20) = 1011101110 = 750
Decimal 27 is 11011 in binary
(27)decimal = (1 1 0 1 1)binary
The decimal number "27" is written in binary as 11011.This is because binary has a base of 2. This means that the digits are representing multiples of powers of 2 (as opposed to 10 in decimal). This number in binary means (1 * 20) + (1 * 21) + (0 * 22) + (1 * 23) + (1 * 24). In decimal this equals 1 + 2 + 0 + 8 + 16. This, of course, equals 27.
100000002 = 27 = 128 in denary (or decimal).
26 decimal is 11010 binary. Its ones complement (in 5 bits) is 00101, which is 5 decimal. In 16 bits, its ones complement is 1111111111100101 which is -27 when interpreted as a signed decimal, and 65509 as an unsigned decimal.
11111112 = 100000002 - 1 = 27 - 1 = 128 - 1 = 127
Binary numbers all consist of combinations of the two digits '0' and '1'. These are some examples of binary numbers: 11010101111101111000000 10101000 00001100 01011101Engineers and mathematicans sometimes call the binary numbering system a base-two system because binary numbers only contain two digits. By comparison, our normal decimal number system is a base-ten system. Hexadecimal numbers (discussed later) are a base-sixteen system. All binary numbers have equivalent decimal representations and vice versa. Our handy Binary-Decimal Number Converter performs these calculations automatically for you. To convert binary and decimal numbers manually, you must apply the mathematical concept of positional values. The positional value concept is simple: With both binary and decimal numbers, the actual value of each digit depends on its position (how "far to the left") within the number. For example, in the decimal number 124, the digit '4' represents the value "four," but the digit '2' represents the value "twenty," not "two." The '2' represents a larger value than the '4' in this case because it lies further to the left in the number. Likewise in the binary number 1111011, the rightmost '1' represents the value "one," but the leftmost '1' represents a much higher value ("sixty-four" in this case). In mathematics, the base of the numbering system determines how much to value digits by position. For base-ten decimal numbers, multiply each digit on the left by a progressive factor of 10 to calculate its value. For base-two binary numbers, multiply each digit on the left by a progressive factor of 2. Calculations always work from right to left. In the above example, the decimal number 123 works out to: 3 + (10 * 2) + (10*10 * 1) = 123and the binary number 1111011 converts to decimal as: 1 + (2 * 1) + (2*2 * 0) + (4*2 * 1) + (8*2 * 1)+ (16*2 * 1) + (32*2 * 1) = 123Therefore, the binary number 1111011 is equal to the decimal number 123. To convert numbers in the opposite direction, from decimal to binary, requires successive division rather than progressive multiplication. Our Binary-Decimal Number Converter also performs these calculations automatically for you. To manually convert from a decimal to a binary number, start with the decimal number and begin dividing by the binary number base (base "two"). For each step the division results in a remainder of 1, use '1' in that position of the binary number. When the division results in a remainder of 0 instead, use '0' in that position. Stop when the division results in a value of 0. The resulting binary numbers are ordered from right to left. For example, the decimal number 109 converts to binary as follows: 109 / 2 = 54 remainder 154 / 2 = 27 remainder 027 / 2 = 13 remainder 113 / 2 = 6 remainder 16 / 2 = 3 remainder 03 / 2 = 1 remainder 11 / 2 = 0 remainder 1Therefore the decimal number 109 equals the binary number 1101101. (Credit to About.com) Binary numbers all consist of combinations of the two digits '0' and '1'. These are some examples of binary numbers: 11010101111101111000000 10101000 00001100 01011101Engineers and mathematicans sometimes call the binary numbering system a base-two system because binary numbers only contain two digits. By comparison, our normal decimal number system is a base-ten system. Hexadecimal numbers (discussed later) are a base-sixteen system. All binary numbers have equivalent decimal representations and vice versa. Our handy Binary-Decimal Number Converter performs these calculations automatically for you. To convert binary and decimal numbers manually, you must apply the mathematical concept of positional values. The positional value concept is simple: With both binary and decimal numbers, the actual value of each digit depends on its position (how "far to the left") within the number. For example, in the decimal number 124, the digit '4' represents the value "four," but the digit '2' represents the value "twenty," not "two." The '2' represents a larger value than the '4' in this case because it lies further to the left in the number. Likewise in the binary number 1111011, the rightmost '1' represents the value "one," but the leftmost '1' represents a much higher value ("sixty-four" in this case). In mathematics, the base of the numbering system determines how much to value digits by position. For base-ten decimal numbers, multiply each digit on the left by a progressive factor of 10 to calculate its value. For base-two binary numbers, multiply each digit on the left by a progressive factor of 2. Calculations always work from right to left. In the above example, the decimal number 123 works out to: 3 + (10 * 2) + (10*10 * 1) = 123and the binary number 1111011 converts to decimal as: 1 + (2 * 1) + (2*2 * 0) + (4*2 * 1) + (8*2 * 1)+ (16*2 * 1) + (32*2 * 1) = 123Therefore, the binary number 1111011 is equal to the decimal number 123. To convert numbers in the opposite direction, from decimal to binary, requires successive division rather than progressive multiplication. Our Binary-Decimal Number Converter also performs these calculations automatically for you. To manually convert from a decimal to a binary number, start with the decimal number and begin dividing by the binary number base (base "two"). For each step the division results in a remainder of 1, use '1' in that position of the binary number. When the division results in a remainder of 0 instead, use '0' in that position. Stop when the division results in a value of 0. The resulting binary numbers are ordered from right to left. For example, the decimal number 109 converts to binary as follows: 109 / 2 = 54 remainder 154 / 2 = 27 remainder 027 / 2 = 13 remainder 113 / 2 = 6 remainder 16 / 2 = 3 remainder 03 / 2 = 1 remainder 11 / 2 = 0 remainder 1Therefore the decimal number 109 equals the binary number 1101101. (Credit to About.com)
try this one 25 + n
11011
1B base 16 = 27 base10
027 = 27 is 27, as a decimal.
27/20 as a decimal is 2.35