# Maximum PC

 It is currently Tue Jul 29, 2014 9:44 pm

 All times are UTC - 8 hours

 Page 1 of 1 [ 6 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Help with C++Posted: Thu Aug 18, 2005 2:47 pm
 Malware specialist

Joined: Sun Apr 03, 2005 12:49 pm
Posts: 11696
Location: Kansas City, KS
Ok, I'm a total noob in programming. I was told to convert numbers from decimal to binary and to hexidecimal. How do I do this? I took notes, but the notes don't really help. If someone can really help me out here, I would really appreciate it.

BTW: The numbers that I was given are like 12, 23, 53, 67, 105. In binary the numbers I was given are 0110, 1101, 0001 1110, 1100 0010. In Hexidecimal I was given 6A, B5, 12D, 30C, A70.

I have to convert each into another format, so help would be appreciated.

Top

 Post subject: Re: Help with C++Posted: Fri Aug 19, 2005 4:20 pm
 Bitchin' Fast 3D Z8000

Joined: Mon Jun 14, 2004 4:04 pm
Posts: 985
Location: Earth
hackman2007 wrote:
Ok, I'm a total noob in programming. I was told to convert numbers from decimal to binary and to hexidecimal. How do I do this? I took notes, but the notes don't really help. If someone can really help me out here, I would really appreciate it.

BTW: The numbers that I was given are like 12, 23, 53, 67, 105. In binary the numbers I was given are 0110, 1101, 0001 1110, 1100 0010. In Hexidecimal I was given 6A, B5, 12D, 30C, A70.

I have to convert each into another format, so help would be appreciated.

None of us are going to do your homework, try first Padawan, and if you don't succeed, then post your initial code. I've told a many Undergraduate Programming students this: if you don't try before you ask questions, you're guaranteed to fail the entire CS program.

Top

 Post subject: Posted: Fri Aug 19, 2005 4:50 pm
 Malware specialist

Joined: Sun Apr 03, 2005 12:49 pm
Posts: 11696
Location: Kansas City, KS
Stupid question, but does this have anything to do with learning C++? I've sort of found out how to do it.

Top

 Post subject: Posted: Fri Aug 19, 2005 4:55 pm
 Bitchin' Fast 3D Z8000

Joined: Mon Jun 14, 2004 4:04 pm
Posts: 985
Location: Earth
hackman2007 wrote:
Stupid question, but does this have anything to do with learning C++? I've sort of found out how to do it.

Yeah, it's supposed to teach you the basics of looping and I/O (at least using IO Stream). I wrote a quick code in C#, but I can easily transfer it to C++, if you want help, again, post your code first.

Top

 Post subject: Posted: Fri Aug 19, 2005 4:59 pm
 Malware specialist

Joined: Sun Apr 03, 2005 12:49 pm
Posts: 11696
Location: Kansas City, KS
My teacher just gave a worksheet full of numbers that were in decimal, binary, and hexadecimal. She told us to convert into each system. Thanks for your help.

Top

 Post subject: Posted: Mon Aug 22, 2005 8:20 am
 Coppermine

Joined: Wed Jul 07, 2004 11:07 am
Posts: 666
Location: Woodland Hills, CA
hackman2007 wrote:
Stupid question, but does this have anything to do with learning C++? I've sort of found out how to do it.

It is how all modern computers represent numbers internally. You need to know this.

Binary numbers and manipulating them will come in handy later down the road.

There will be times when you are coding that you need to use something called a bit-mask. Which can be used in binary or hex form. I use it quite often when I do some network programming and even html programming.

Here is an example.
Color representation on a computer is typically represented by a 3-tuple normally called RGB values. For example, a white colored pixel has the value (255,255,255) while a black color pixel has the value (0,0,0). Pure red is (255,0,0), pure green is (0,255,0) pure blue is (0,0,255).

It takes 8 bits to represent 256 numbers. In RGB color representation, a computer uses 8 bits for red, 8 bits for green, and 8 bits for blue, (and sometimes 8 bits for transparency). Since we need 24 (or sometimes 32) bits to represent a pixel, it is perfect to use an int(eger) since an integer uses 32 bits. That means you can pack a pixel value consisting of 3 colors (and possibly a transparency value) all into just 1 integer.

So for example, pure white can be represented by...

red = 11111111
green = 11111111
blue = 11111111

So in a 32 bit (big endian) system (don't worry about the big endian term for now), you could represent pure white with an int value that is equal to
a binary of:11111111111111111111111100000000 where the first 8 bits of the 32 bit int represents red, the second 8bits represent green, and so on.

That huge binary number is a pain in the ass, so Hex numbers are used.
So...hex numbers have this property where 4 bits can be represent by just 1 hex digit.

For example:
15 (decimal) = 1111 (binary) = F (hex)

Example 2:
10 (decimal) = 1010 (binary) = A (hex)

Now let's go back to the color example I used earlier...
A color of (255,255,255) packed into one integer can be represented in binary by: 11111111111111111111111100000000

We can represent that in a much easier way by "breaking it up" into smaller pieces and converting it to hex... Take 4 binary bits at a time and convert them to hex...so we get
FFFFFF00.
Each "F" represent 1111.

You can even see web pages use this hex concept...for example:
If I want to use a red background for a web element, I would specify:
bgcolor=#FF0000
Which represents 111111110000000000000000 which if you split this binary number into 8 bit groupings, you get 11111111 00000000 0000000 which represents (255,0,0) which is red.

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 6 posts ]

 All times are UTC - 8 hours

#### Who is online

Users browsing this forum: No registered users and 2 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ Maximum FAQs    Forum Rules, Posting Guidelines & Announcements    The Good, The Bad & The Banned    FAQs Help/Do It Yourself    PC Building Lab    The Help Desk    PC Modding    Education & Certification Hardware    Nuts & Bolts    Portable Talk    Appraisals, Deals & Bargains (oh my!) OS/Software/Programming    Windows Parlor    Alt.OS.Abode    Games Arena    Programmers' Paradise Networking/Internet    Internet Truckstop    Network Nook In/Out    Magazine and Book Feedback    Forum & Website Feedback    Dog Pound Team Maximum PC Folding at Home    Team Maximum PC - Folding at Home - FIND CURES TO DISEASES    Team MPC - Folding Gauntlets