Quantcast

Maximum PC

It is currently Sat Oct 25, 2014 4:52 am

All times are UTC - 8 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Help with C++
PostPosted: Thu Aug 18, 2005 2:47 pm 
Malware specialist
Malware specialist
User avatar

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
  Profile  
 
 Post subject: Re: Help with C++
PostPosted: Fri Aug 19, 2005 4:20 pm 
Bitchin' Fast 3D Z8000
Bitchin' Fast 3D Z8000
User avatar

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
  Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 4:50 pm 
Malware specialist
Malware specialist
User avatar

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
  Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 4:55 pm 
Bitchin' Fast 3D Z8000
Bitchin' Fast 3D Z8000
User avatar

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
  Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 4:59 pm 
Malware specialist
Malware specialist
User avatar

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
  Profile  
 
 Post subject:
PostPosted: Mon Aug 22, 2005 8:20 am 
Coppermine
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
  Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 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 forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

© 2014 Future US, Inc. All rights reserved.