Binary Numbers
Base system uses base B, and includes numbers 0, 1, 2, ... , B‑1
For example in decimal system B=10, and numbers included are 0, 1, 2, ..., 8 & 9.
If the base B=2, then the system is binary, and its numbers are 0 & 1.
From English term BInary digiT, comes the name for lowest amount of information BIT.
Example:
5710 = 5 * 101 + 7 * 100 = 1*25 + 1*24 + 1*23 + 0*22 + 0*21 + 1*20 = 1 1 1 0 0 1 2
Number 57 in decimal is shown by two numbers, while in binaries six figures are necessary to show data. Binaries compared to other numbering systems, logically use most amount of elements (data) to give us information. Number of BITS used to write down a number is limited due to technical reasons.
Machines used to process and save binary information, are usually constructed form electronic elements with 2 stable states (bistables), which are efficient and cheap to produce.
Switching from decimal to binary numbers:
Binary number is made by leftovers we get from dividing (reading upwards)
57 : 2 = 28 1 1 1 0 0 1
1
28 : 2 = 14
0
14 : 2 = 7
0
7 : 2 = 3
1
3 : 2 = 1
1
1 : 2 = 0
1
If we have n=3 bit length registry, (first bit reserved for telling us if its –/+), next numbers can be shown:
Decades Binaries
0 000
1 001
2 010
3 011
-4 100
-3 101
-2 110
-1 111
For n = 3 we get interval [‑22, 22 ‑ 1], in general [‑2n‑1, 2n‑1 ‑ 1].
For n = 8 we get interval [‑27, 27‑1], exact range [‑128, 127].
Octal System
Base of the system is B=8 and numbers used are 0, 1, 2, 3, 4, 5, 6, 7.
This system is used for shorter description of binaries when its needed.
Example:
36‑bit number 001 110 000 101 111 001 010 011 111 000 100 001
Octal equivalent 1 6 0 5 7 1 2 3 7 0 4 1
Hexadecimal System
Base of the system is B=16 and numbers used are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F. This system is used for shorter description of binaries when it’s needed.
Example:
16‑bit number 0111 1011 0011 1110
Hexadecimal equivalent. 7 B 3 E
Rational numbers
Rational numbers have binary “spot” which is similar to decimal spot used by decimal numbers.
Example: conversion of rational number
5.75 10 = 5 * 100 + 7 * 10‑1 + 5 * 10‑2 =
= 1*22 + 0*21 + 1*20 + 1*2‑1 + 1*2‑2 = 1 0 1 . 1 1 2
Conversion of decimal number to binary number
Example: conversion of this decimal number - when conversed, it has infinite number of fractions in its binary state
Notice that finite decimal number is shown as infinite periodic binary number.
Binary Number is mounted with exponent of Base 2, in a way that a binary dot is moved left or right, depending if exponent is positive or negative
Example: 1 . 1 1 * 22 = 1 1 1
Update - March, 8. 2006: Don't panic! if you didn't quite understand these numerical systems, You can still read my additional lesson that should in-depth cover this topic. There are many examples on numeric conversions also. Soon, I'm going to post another lesson on calculations with binarie numbers.
is there gonna be some tutorials in visual c++?
I constanty check ur LordofNet blog. Nice work
thank you both. there is gonna be tutorials every few days. first topic im covering is intro to computer language foundations, then programming in c (getting used to a code) then algorithms and structure of data, (lysts, files, etc. with c) then c++ tutorials... ...
in shot you'll learn from zero to making advanced programs yourelf!
this is great opportunity for all of you to follow my work and learn with almost no effort just by reding every few days this site, but I'll also include some homework for you guys, and already included some nice examples in tutorials
Nice try. Keep up the good work.
Good stuff, a little confusing but good stuff. ^ ^
Shouldn't a set of tutorials on C start with lesson 0? :-)
If you wan't to get technical, yes. But in that case I think I would put it:
0
01
10
11
100
101
110
111
...
..
.
and so on for every following lesson ;)
Most c Tutorials start with HelloWorld and introduce some Keywords in C.. You start first with the basics (like this capter). I think this approach is much better since the reader will understand better how his/her computer works.
Thanks for writing this tutorial and keep up the good work!
sorry, but this tutorial is only understandable until negative binary numbers - you did not add any comment to help a newbie understand it (complement till base -
what's a 'base'?, there's no explanation). if you want your tutorials to be helpful, you need to be more informative. i apperciate the effort, but i doubt that someone who didn't use binary before, will learn it from this lesson.
look at the beginning of the article and if you read it you will see Base explanation.
Cool! Thanks for taking the time to provide such a useful resource. I hope many people use it.
i understand positive binary numbers (i have a degree in networking) but you lost me at negative binary numbers. if you could further explain this i would be grateful. i'm currently pursuing a degree in web programming and would like to gain some understanding of the more powerful, lower-level, C language.
I have to agree with naters and stipa (partially). You lost me at negative binaries; what is a complement till base? The rest of the tutorial was mildly informative, probably not for n00bs.
I have no understanding of programing. I'm fairly proficient in using and repairing computers. I'm just wondering, am I out of my league in trying to understand this stuff or is there some prerequisite you recomend for me?
Without reading any of the other lessons, I'm just curious why you would want to start out with binary number. The whole purpose of using a high-level programming language is to abstract away having to know a thing about binary.
After being out of high school math for 27 yrs, I got left behind at the first paragraph. Can anyone suggest a pre-tutorial that covers binaries, etc. more thoroughly?
In response to Luke, if one is to properly use C one must understand how it stores data. The power and efficiency of C derives in part from its ability to directly access memory, which in effect makes it very dangerous (e.g. buffer overflows). There is no protection against improper memory access, and there is no garbage collection. C is not as high level as most other languages used today, and requires more attention to technical detail. I could go on for ever about this, but it's not my tutorial. That being said, I think verdlak is doing a great job.
Negative Binary Numbers part is very Confusing.
so which method do the computers (let's say intel based) use to store the negative numbers? sign & magnitude or 2's compliment?
Hy,
I'll post add-on soon to this lesson explaining more on computer storage of binary numbers. This lesson is written in order for you to get a feeling how computer reads and stores data in bits, but isn't required to understand in depth. Anyhow I'll work on follow-up to this lesson where I'll go little offtopic lecturing you more on binary data and computer storage, and post it here in few days.
Answer to Ada:
Computer stores numbers in NBC, 1' complenet, 2' complenet, BCD... or some other variant, but 2' complement is most spread way of stgoring positive and negative numbers which ALU (arithmetic-logical unit) can understand.
Please allow me few days to compose an article where I'll publish more detailed description of NBC (most basic storage of positive numbers), 1' complement, 2'complement, BCD, and operations done used previously mentioned methods of storing data.
Update - March, 8. 2006: Don't panic! if you didn't quite understand these numerical systems here, You can read through my additional lesson that in-depth covers them all; conversions also. Soon, I'm going to post another lesson on calculations with binarie numbers.
when shall u put something more interesting then these highschool programming ? cant u put bit profesional?
i have no idea what the negative binary numbers are doing haha, i get everything else, but the negative binary
Somewhat different approach to start a C tutorial but looks good, keep up the good work!
good material! the presentation is good as starting material
good job......one quick question....how can I get compilers? and can I ask questions to clear my doubts?
I want to study programming c
you guid me about it