This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Binary/Octal/Hex and Decimal Number Systems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Binary/Octal/Hex and Decimal Number Systems" Watch "Binary/Octal/Hex and Decimal Number Systems" New topic
Author

Binary/Octal/Hex and Decimal Number Systems

mert �zkaya
Ranch Hand

Joined: Jan 26, 2006
Posts: 33
Hi everyone,
In spite of working on it , I still do not understand them exactly , only a little bit.

Can anyone please explain them shortly by giving examples??

Thanks,

Mert
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11256
    
  16

the different number systems simply refers to how many digits you can use. humans use 10 digits... 0-9.

to count, we start cycling through them all. when we run out, we start using two digits at a time. when we run out of every possible 2-digit combination, we go to three.

so a number like 243 really means

2*10^2 + 4*10^1 + 3*10^0.

each position simply means a higher power of 10. why powers of 10? becuase we use decimal base.

if we used Octal base, we only get 8 digits (0-7), and we use powers of 8.

245 in octal means

2*8^2 + 4*8^1 + 3*8^0.

hexadecimal uses 16 digits. 0-9 and then a-f. you can see numbers like

2a7 which would mean

2*16^2 + 11*16^1 + 7*16^0


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
mert �zkaya
Ranch Hand

Joined: Jan 26, 2006
Posts: 33
Thanks very much for your instructive explanation...

Mert
mert �zkaya
Ranch Hand

Joined: Jan 26, 2006
Posts: 33
Hi everyone,
CAn anyone also explain Binary systems by giving some examples?

Thanks,

Mert :roll:
Guy Allard
Ranch Hand

Joined: Nov 24, 2000
Posts: 776
I recently saw this which describes teaching binary to 3rd graders using the Socratic method. I thought it was interesting.

Teaching Binary

Regards, Guy
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Originally posted by Guy Allard:
I recently saw this which describes teaching binary to 3rd graders using the Socratic method. I thought it was interesting.

Teaching Binary

Regards, Guy


That's pretty cool!

mert, you should skip down the page to where the questions start. I think the questions and answers will help you understand binary numbers.

Layne


Java API Documentation
The Java Tutorial
mert �zkaya
Ranch Hand

Joined: Jan 26, 2006
Posts: 33
Hi,
I would like to know that why is binary System is prefered instead of decimal System ?
In other words , what is the advantage of using binary System instead of decimal System ??

Thanks,

Mert
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
It seasier for computers to count in the binary system becausr there are only two states. 0 or 1, off or on, low voltage or high voltage. However you want o think of it. Think of a light switch, it only knows two states, either its off or its on. Its the same reasoning for computers working in the binary system. The computer doesnt have to, or need to keep track of ten different states (0 - 9) just two states (0 -1) off or on.


Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
mert �zkaya
Ranch Hand

Joined: Jan 26, 2006
Posts: 33
Ok,
GArrret, I understood what you meant. But is there any advantage of using Binary for programmers ??

Thanks,

Mert :roll:
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by mert �zkaya:
GArrret, I understood what you meant. But is there any advantage of using Binary for programmers ??


Two things come to mind:

- as the computer uses the binary system anyway, some oddities are easier to understand once you understand the binary system (for example, why 0.1 decimal can't be represented exactly in a float/double).

- you can "misuse" numbers as sets of booleans - by treating every bit of an int as a boolean, for example.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
mert �zkaya
Ranch Hand

Joined: Jan 26, 2006
Posts: 33
Originally posted by Garrett Rowe:
It seasier for computers to count in the binary system becausr there are only two states. 0 or 1, off or on, low voltage or high voltage. However you want o think of it. Think of a light switch, it only knows two states, either its off or its on. Its the same reasoning for computers working in the binary system. The computer doesnt have to, or need to keep track of ten different states (0 - 9) just two states (0 -1) off or on.


Hi,
Can anyone give some examples about the hardwares??

Thanks,

Mert
Curtis Brown
Greenhorn

Joined: Jan 10, 2006
Posts: 20
An other reason you may want to program with binary values...

Something that you might have occasion to do, as a programmer, is set up a bit-register of flags... what I mean is, maybe you have a one-byte (8-bit) set of flags, where each bit represents some toggle in your program....



Then, what you'd want to do is use the "bitwise" operators, OR, AND, XOR (exclusive or), or the bitwise complement. In java the operators are |, &, ^, ~, respectively.

Depending on if you wanted the flag to always toggle, only toggle if off, only toggle if on, etc. you'd use a different operation.

Now, as to the hardware issue, the way microchips work is by deciding if any message is a 1 or a 0 based upon voltage. You could make hardware that appeared to "think" in decimal, but it would be because you designed a hardware abstraction layer that obfusicated the binary qualities from the programmer... there really wouldn't be any point in doing this, as it would be cumbersome, and have less robust functionality than we currently have at our disposal.

Maximilian Xavier Stocker
Ranch Hand

Joined: Sep 20, 2005
Posts: 381
Someone with the username mert has been trolling on the Sun Forums with these exact same questions as posted by mert �zkaya in these forums. The only difference being that on the Sun forums mert has been more overt by means of cursing and vague threats towards others.

At any rate mert appears to exhibit many troll like tendencies and behaviours. Just warning.

Compare this thread and http://forum.java.sun.com/thread.jspa?threadID=703144&messageID=4076946 for example.
mert �zkaya
Ranch Hand

Joined: Jan 26, 2006
Posts: 33
Yeah, Good diagnosis.
It is the rule of my Game...
Be happy , do not worry...
Maximilian Xavier Stocker
Ranch Hand

Joined: Sep 20, 2005
Posts: 381
Originally posted by mert �zkaya:
Yeah, Good diagnosis.
It is the rule of my Game...
Be happy , do not worry...


When you say "rule of my Game" I can only interpet that to mean that you are confirming that you are in fact a troll. You said this a couple of times at Sun along with "this is a joke".

I don't believe trolls are desired elements here.

And you just sent me a private message that I will be forwarding to a moderator that reads

"We are Muslim ,we are Turk.
We are not afraid of smo. "

Which I can only guess means you are a troll on a jihad. Lovely.
 
 
subject: Binary/Octal/Hex and Decimal Number Systems