GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rating: Thread Rating: 14 votes, 4.79 average.
  #1  
Old 11-May-2004, 13:36
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,328
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: Conversion: Binary, Decimal, Hex


I just posted a GID Community blog entitled: Conversion: Binary, Decimal, Hexadecimal.

Quote:
To Convert Or Not To Convert. That is the Question.

One of the big questions I see on GIDForums™ is, How do I convert decimal to hex? Once you understand the difference between the computer's use of binary, decimal, and hexadecimal you'll understand why the question as asked is a non-question. It's like asking the difference between ice and frozen water. read more...

Please let me know what you think.

This is an auto-generated message posted by GIDNetwork™ on behalf of the author.
__________________

During the election they said Obama could only be elected when pigs fly. Well, we currently have an epidemic of Swine Flu. Coincidence?
  #2  
Old 10-May-2006, 06:49
davis
 
Posts: n/a

Re: Conversion: Binary, Decimal, Hex


Quote:
Originally Posted by WaltP
I just posted a GID Community blog entitled: Conversion: Binary, Decimal, Hexadecimal.



Please let me know what you think.

This is an auto-generated message posted by GIDNetwork™ on behalf of the author.


CPP / C++ / C Code:
char string[33];    // assuming 32bit integers

...why assume? Aren't we aware of sizeof( int ) already?

CPP / C++ / C Code:
char string[ sizeof( char ) + (sizeof( int ) * BITS_IN_A_BYTE)];

I can appreciate your interest in keeping the code possibly less confusing to novices, but hardcoding magic values like "33" probably sends the wrong message, doesn't it? I believe that conventional thinking tells us that the only magic numbers in a program should be "0" or "1," which lends nicely to a discussion on conversion! However, I tend to favor 0, 1 and -1...and then it is really hard not to accept "2," particularly for finding evenness/oddness, but then that leads us to 8, 16 and many more...even to the point where we get 33 and, then, really any magic number is okay afterwords, right? In fact, the discipline of using magic numbers is vastly overrated, don't you think?

Of course, there are those who would argue that the macro BITS_IN_A_BYTE only marginally "more" portable.


:davis:
 
 

Recent GIDBlogReview: Gel laptop cooling pad by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
NFA to DFA conversion fiddler_808 C++ Forum 3 02-Jun-2006 12:49
problems typecasting an int to a string holbrook C++ Forum 9 07-May-2004 18:59
Decimal to Hex conversion function machinated C++ Forum 0 07-May-2004 17:33
Help with binary files (encryption?) pablowablo C++ Forum 6 28-Apr-2004 22:47

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 10:08.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.