User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 403,317 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,979 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums

Number Conversions

Join Date: May 2008
Posts: 84
Reputation: n1337 is on a distinguished road 
Rep Power: 1
Solved Threads: 7
n1337 n1337 is offline Offline
Junior Poster in Training

Re: Number Conversions

  #2  
May 11th, 2008
Hi, this is my first time posting to this forum so please let me know if I'm doing anything wrong.

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...

a. Write the internal representation of “17” in ASCII using two binary numbers

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;
cout << (int)'7' << 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

b. Write 17 and -17 in two’s complement notation. Use 8 bits for each

Again, quick google search will reveal how two's complement works. Here you go:

http://en.wikipedia.org/wiki/Two's_complement

c. Write 0100101111112 in hexadecimal and 3F16 in binary

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!
Last edited by n1337 : May 11th, 2008 at 7:38 pm.
Reply With Quote  
All times are GMT -4. The time now is 7:33 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC