![]() |
| ||
| Number Conversions Hi, this is my first time posting to this forum so please let me know if I'm doing anything wrong. I would like to know how to do the following... a. Write the internal representation of “17” in ASCII using two binary numbers b. Write 17 and -17 in two’s complement notation. Use 8 bits for each c. Write 0100101111112 in hexadecimal and 3F16 in binary I would appreciate your help, thanks. |
| ||||
| Re: Number Conversions Quote:
I'm fairly new here also, so I can't tell ya...But as a general rule, I think it is best if you try to search for things on your own before posting... Quote:
I'm not totally sure what you mean by this, but you can get the ASCII character codes by using the following code: cout << (int)'1' << endl; In fact, you can find out any character code by replacing the 1 or 7 with whatever character you like. Anyway, the above code will give you 49 and 55, respectively. So I suppose you need to write these numbers in binary...As for doing that, there are several algorithms (to do it by hand), which you can mimic using code (if you need to). I'm sure there is also probably some function written in some library in C++ that will auto convert for you, or you could write one yourself (do a search if you desire). Anyway, the following link explains a few "by hand" algorithms for converting decimal to binary: http://www.wikihow.com/Convert-from-Decimal-to-Binary Quote:
Again, quick google search will reveal how two's complement works. Here you go: http://en.wikipedia.org/wiki/Two's_complement Quote:
I would suggest doing this in two steps, converting first to base ten (decimal) in both cases, and then from decimal to the appropriate base. However, there are also ways of converting directly from hex to binary and vice versa. (Remember, hex is base 16, so maybe you can find a pattern between groups of 4 bits and their hex equivalents...sorry if that sounds cryptic but again, there are tons of references and algorithms on the net, so it would be redundant for me to explain here...) Good luck! |
| ||
| Re: Number Conversions For C you can use these functions: #include<iostream> |
| ||
| Re: Number Conversions thanks a lot william, but I don't need the functions. I just need the results, it's for a C++ class assignment. I'm not expecting anyone to do it for me but if someone could explain me how would I go about converting them, that would be great. Thanks again though for all that. |
| ||
| Re: Number Conversions hi,
Maybe it s that what you are looking for :) krs, tesu |
| ||
| Re: Number Conversions thanks to tesuji for the answer. |
| All times are GMT -4. The time now is 2:39 am. |
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC