how do i convert hexadecimal value into decimal values in c ?
341598
If you want to convert a hex string to decimal, you\nneed to do two operations:\n\n- convert the hex string to a number\n- generate a decimal string from that number\n\nIf your system supported a full C implementation,\nit would be as simple as using scanf()/printf().\nI presume you're being asked to implement the\nprimitives yourself :-)\n\nTo convert a hex string to a number, you might\nimplement something like:\n\nint number = 0;\nwhile ((c = getchar()) != '&#92;n') {\n  if (c >= '0' && c <= '9')\n    number = (number<<4) + (c-'0')\n  else if (c>='a' && c<='f')\n    number = (number<<4) + (c-'a')\n  else if (c>='A' && c<='F')\n    number = (number<<4) + (c-'A')\n}\n\nThis could be cleaned up if you have access to the\n<ctype.h> macros [ie. isdigit() and tolower()].\n\nTo convert the number to a decimal string, you need\nto perform successive divisions by 10.  An 8051\ndoesn't have a hardware divide, but that's OK\nbecause you should have a software divide/remainder\nsubroutine.\n\nThere are two tricks to keep in mind.  First to\ngenerate the appropriate character for each digit,\nyou can treat a literal character string as an\narray.  For example:\n\nchar c = "0123456789ABCDEF"[i];\n\nwill assign the correct character to variable "c"\nbased on the value of "i" (if it is between 0 and\n15).\n\nThe other detail is that as you call the divide/\nremainder subroutine, you will generate the digits\nworking from least significant to most significant.\nTherefore, you'll want to fill an array from right\nto left.  Assuming you have a divide routine with\nthe prototype:\n\nint\ndivide(int dividend, int divisor, int *remainder)\n\nand you can use the "puts()" function to display the\ngenerated string, you might use something like:\n\nvoid\ntodecimal(int value)\n{\n  char buffer[20];\n  char*p = &buffer[sizeof(buffer)-1];\n  int remainder;\n  while (value != 0) {\n    value = divide(value, 10, &remainder);\n    *p-- = "0123456789ABCDEF"[remainder];\n  }\n  puts(p+1);\n}
849927
I don't see why the sign should matter; just add it back at the end.\n\n3056 Decimal\n\nDivide by 16 - no remainder - 191\nDivide by 16 - remainder 15 - 11\nDivide by 16 - remainder 11 - 0\n\nSo, 3056 in hex is BF0\n\nBasically keep dividing by 16 until the number is 0. Then take the remainders and create the number.
295060
That's hexadecimal, you can convert it to ASCII with many online tools such as http://www.vortex.prodigynet.co.uk/misc/ascii_conv.html
840338
In windows, open up the calculator.\nGo to scientific mode.\nSelect "Bin".\nType in the binary number.\nSelect "Dec"\nThe number is now displayed in decimal.\n\n4\n5\n12\n21\n15\n185\n154
522185
If you're using windows, the calculator program that comes with the system should be quite adequate. It will even allow you to perform your binary-to-decimal conversion easily. Just switch the calculator mode to scientific (under the view menu), select bin (upper left corner), type in your binary number, and select dec, and there is your answer.\n\nIf you're not using windows... try someone else's advice.
220005
Use a string. Calculate the first 16 digits, then put them into a string and subtract that number from your value and then use it as though its scientific notation. For example\n3.141592653589793 is the first 16 digits. So convert that to a string and then multiply your deriving value by 1,000,000,000,000,000 and start again. Then strip out the decimal and append to the string\n"2384626433832795"\nand then\n"0288419716939937", "5105820974944592", "3078164062862089",\n"9862803482534211", etc. \n\nThis should allow you a very large item.\n\n\nThe other option I can think of is declare an array 5 or 10 digits each and then store the numbers in there. That might work.\n\n\nEither way, good luck!
163804
Continuously divide the decimal number by 16 and stack up the remainders at each stage, until you finally reach a divisor that is less than 16. Of course, you have to write the remainders above 9 in the alphabetical form - 10=A, 11=B and so on till 15=F. Finally, string the final divisor followed by the stack of remainders read backwards to obtain your hex number.\n\nAlternately, if you are good at converting between decimal and binary, do that and then read off the binary bits from the end in groups of four in the equivalent hex. For example, if after decimal-to-binary conversion, you were to get\n11100011010101, then group them as\n(0011)(1000)(1101)(0101). Now, this is equivalently 38D5 in hex.
966120
try this stuff... pls understand the logic...\n\n#include<stdio.h>\n\nint main()\n{\nint no,rem;\nscanf("%d",&no);\nwhile (no)\n{\nrem = no % 10;\nprintf("%d",rem);\nno = no / 10;\n}\n}
612486
This is pretty straighforward in C - I won't write the assignment for you, but the general proccess is as follows:  \n\n1.  Count the number of each coin - store that number in some variable (say, int num_dimes;  )  If you're reading from a file, it's a little more complicated, but if your user is entering something from a command line (as is the case with beginning programming assignments, usualy) it's just a matter of having them enter a number and using a function like get() to read the input.  \n\n2.  Multiply the number of each coins by the appropriate denomination.  For example - if you counted 6 dimes in the previous step, multiply 6 by .10.  Make sure that you store the result in a floating point variable, and it's generaly a good idea to ensure that you're multiplying two floats together in order to get a float answer.  Use something like this:\n  \nfloat dimes_total; \ndimes_total = (float)num_dimes * 0.10;   \n\nthe (float) in front of num_dimes casts that variable as a floating point number.  \n\n3.  After you've done this for each coin, simply add up the totals: \n\nfloat total; \ntotal = pennies_total + nickles_total  ... etc, etc.\n\n4.  print your answer to the screen - since dollars and cents use the same number base as arithmetic done by the compiler, nothing fancy is needed here.    In cases where you're dealing with different number bases, however, it gets to be a little more tricky.
161655
Divide the decimal number by 16.   Treat the division as an integer division.   \nWrite down the remainder (in hexadecimal). \nDivide the result again by 16.  Treat the division as an integer division.   \nRepeat step 2 and 3 until result is 0. \nThe hex value is the digit sequence of the remainders from the last to first. \ncheck here: http://www.permadi.com/tutorial/numDecToHex/
807970
move the decimal point two places to the right (or multiply by 100)\n\nso\n\n0.005049 becomes 0.5049 %
400127
C  H   O\n.6  12   6\n\nWITHOUT DECIMAL POINT
1159013
How does this work?  Is it okay to have a decimal in the middle?\n\nType 1   (Screen says 1)\n/ 3          (Screen says 0.3333333)\nx 3         (Screen says 0.9999999)\n+ 9        (Screen says 9.9999999)\n\n- Jack
114514
I have the answer.\n\nYou should change the numbers to be "400.0" instead of "400". This is your primary problem.\n\nThe deeper reason that this is happening is that 400*400/400 is an INTEGER expression. It will be evaluated as an integer, and only assigned to a floating point result.\n\nI believe that your compiler is a 16 bit compiler, this is the only answer that makes sense.\n\nNow let's just see what the compiler is doing. Its first step is to evaluate 400*400. Now if you get out your calculator, you will get the answer 160,000. NOT SO FAST!!!! An integer in your compiler is only 16 bits long, and can only express numbers between -32768 and 32767. The answer that it comes up with is 28,928 (160,000 - 2*65,536). It will next divide 28,928 by 400 to give 72 (again it drops the fractional result because it is integer).\n\nIn both C and C++, the result of an integer expression is an integer. It does not matter if it gets assigned to a float or not. If you want float accuracy, then the numbers in the expression must be floats.
227540
001100100001\n\nSorry braxton_paul, you're second answer is incorrect, as it is binary, BCD, or BINARY CODED DECIMAL, is different. as stated by wd5gnr, BCD wastes space, this is why the BCD number is 12 digits, and your binary is only 9. This is due to the fact that BCD has no base (at least in the normal sense), wheras binary is base two. Just because BCD uses only two characters, doesn't mean its base is two. This is due to the fact that BCD has no "place weight", for example, if you have 95473 (for a random example), in a base 10 (decimal) system, the 4 would have a value of 400. Say you have a binary system, and lets just use the BINARY of 321, or 101000001, (from RIGHT to LEFT) the ones place has a "weight of 1, the two's has a weight of 2, the three's has a wieght of 4, position 4 is 8, 5 = 16, so forth (each time you multiply the previous space by two)... So to convert BIN to DEC, just multiply the digit ocupying the space by the spaces value, so from right to lef, you would get 1x1=1, (the zeros do not matter since anything times zero is zero) 1x64=64, and 1x256=256... then simply add the values together, and you get the DEC equiv. of your BIN, so 1+64+256=321... Just try that with BCD... and you do indeed get 801... that is why it is called binary CODED DECIMAL. the lack of a base is why BCD can only easily be converted to and from Decimal and Binary, just try converting it to octal, or hex... it is a pain in the a$$ unless you first convert it to DEC...\n\nso (as if anybody cares):\n\n321 (DEC, or base ten) = 141 (HEX, or base sixteen) = 501 (OCT, or base eight) = 101000001 (BIN, or base two) = 001100100001 (BCD, or base ten incoded in base two)\n\nwheras:\n\n801 (DEC) = 321 (HEX [coinciednce]) = 1441 (OCT) = 1100100001 (BIN) = 100000000001 (BCD)\n\nBinary, and (B)inary (C)oded (D)ecimal are not the same!\n(and wd5gnr's BCD to DEC conversion table is correct)\n\nUsualy a dead give away when it comes to BCD vs. BIN, is that BCD usaly has preceeding zeros listed, but BIN does not (though preceeding 0's could also mean ASCII, BCH, or BCO, or prettymuch binary coded anything)
535427
To do this, you have to do sin^-1 * decimal. Because Yahoo Answers only displays up to .0145, I'll do sin^-1 * .0145, which would be about 0.8308
274854
The difficult thing here is reading and writing the numbers. They must be transformed from ASCII and then the result transformed back to ASCII.I found a program that calculates the sum of 2 numbers.I hope it helps.