このページはEtoJ逐語翻訳フィルタによって翻訳生成されました。

翻訳前ページへ


Overview of Binary- for programmers HOME - - - - - - - - - - - - - - - Other 構成要素 for programmers

- - - - - - - - - Pascal Tutorials (米)棚上げする/(英)提議する of Contents
- - - - - - - - - Arduino Tutorials (米)棚上げする/(英)提議する of Contents

Overview of Binary, with Pascal and C code.


The people working on the 金物類/武器類 of 早期に computers were delighted when the ソフトウェア people told them that only two 明言する/公表するs were needed inside the machine. You or I might try to make an analog computer, one that used, say, 1 volt to stand for "1", 2 volts to stand for "2", etc. Making such 回路・連盟s is possible.... just tedious. It is easier to make 回路・連盟s which only need to be "clever" enough to 持つ/拘留する two values, usually called "off" and "on", or "無" and "one". I'm not espousing the belief that "平易な=good", but if you can 避ける the 複雑化s of showing 1,2,3... with different voltage levels, then you can spend more time making your machine more reliable, and more clever in other ways.

We call the two 明言する/公表する computers "数字表示式の", even though "binary" would be a better 指名する.

So. Everything inside the computer is, at one level, a one or a 無. How?

Think first about the decimal numbers we use every day. Even though we only have 10 digits (0,1,2,3...8,9), we can still show numbers bigger than 9, can't we? Likewise in the binary system we can show numbers bigger than 1 by using several BInary digiTs (often called "bits") together. It is the same thing that we do with language. 26 letters. Many, many words. Within the computer, groups of bits are 接近d together, often groups of eight. A group of 8 bits is called a byte. I believe the 見解(をとる) that says "byte" (機の)カム from talking about using the bits "eight-by-eight", as in "the animals entered 2-by-2". At the time "byte" was coming into use, using bits in 8 bit groups was not as ありふれた as it is today. The first computer I programmed worked with 12 bit groups. Though we won't use it again, I'll について言及する in passing that the word "word" is used when talking about the number of bits usually used by the computer 存在 discussed. Thus, even though "byte" always means 8 bits, the number of bits in a word 変化させるs from computer to computer. (It also has another use.)

All computers have long 名簿(に載せる)/表(にあげる)s of numbers 蓄える/店d in them. At least one of those 名簿(に載せる)/表(にあげる)s is not lost when the computer is switched off. (Such a 名簿(に載せる)/表(にあげる) is called "非,不,無-volatile") The computers are built so that when they are turned on, the number at the 長,率いる of a particular one of those 非,不,無-volatile 名簿(に載せる)/表(にあげる)s is fetched into a special place in the computer. That number tells the computer what to do next. In some 事例/患者s more (警察などへの)密告,告訴(状) is needed for what comes next, and that (警察などへの)密告,告訴(状) will be held in the next number in the 名簿(に載せる)/表(にあげる). I'm わずかに oversimplifying here, but not too much, when I say that the first number might have been a general code for "You need to put something on the 監視する". Built into that 指示/教授/教育 would be that WHAT to put on the 監視する is to be 設立する as the next number in the 名簿(に載せる)/表(にあげる), and that the number is held in the ASCII code. Now, written in binary, the code for "A" is 01000001. In the simplest code (there are others) for 変えるing binary to decimal, 01000001 is 65... but who cares? At the moment, the 1s and 0s are 存在 解釈する/通訳するd as a way of 明示するing squiggles which "mean" nothing to the computer. It just puts those squiggles on the 監視する, and our brains 解釈する/通訳する them.

So... one group of eight 1s and 0s... one byte... may be a code for what the electronics should do. Another byte may be a code for a squiggle. In another シナリオ, the 指示/教授/教育 might be for putting a number of squiggles on the 監視する. The first byte after the 指示/教授/教育 might again say WHICH squiggle, and the second number after the 指示/教授/教育 might be a code for HOW MANY of them to put on the 審査する. At last! A byte standing for a number!

How does the computer tell an 指示/教授/教育-byte from a squiggle-byte from a number-coding-byte? It's all in how you (機の)カム to it. Thus the need for the computer to start up at a known place in a 非,不,無-volatile 名簿(に載せる)/表(にあげる) of bytes. The first one WILL be 解釈する/通訳するd as an 指示/教授/教育. その後の bytes will be 解釈する/通訳するd によれば the 需要・要求するs of the bytes which have come before them.

So how does the computer ever do anything beyond a 選び出す/独身, repeated 仕事? There are ways to get bytes into the electronics 経由で a keyboard. The computer will be programmed to do さまざまな waking-up 仕事s, and then it will settle into a 宙返り飛行 that says "Have I been asked to do anything?" If not, it just asks the question again. If, however, the human outside has 圧力(をかける)d a 重要な on the keyboard, or moved the mouse, or 類似の, then the computer can "see" that, and "see" which 重要な. Depending on which 重要な, it then moves on to other 名簿(に載せる)/表(にあげる)s of bytes, and 作品 its way through them. The numbers in those 名簿(に載せる)/表(にあげる)s may change, either because the human types in new stuff, or because the human 教えるs the computer to go fetch a 名簿(に載せる)/表(にあげる) from, say, a レコード.

SOMETIMES (not always) we need to be able to 変える between binary numbers and decimal numbers. Do remember that either is 単に one way of 令状ing something, another "code". "12", "twelve", "a dozen", "douze" and "6+6" are all the same thing, really.

IF we are using simple binary numbers 100 and 4 are two ways of 令状ing the number of fingers on a 手渡す (not counting the thumb.)

We talked どこかよそで about 変えるing from bytes to numbers. To recap:

In the simplest binary to decimal 転換 計画/陰謀...
The decimal number 0 is the binary number 0
The decimal number 1 is the binary number 1
The decimal number 2 is the binary number 10
      "            3          "           11...
Decimal... binary...
  4         100
  5         101
  6         110
  7         111
  8        1000
  9        1001
  10       1010... etc.
  ....
  ......
  252  11111100
  253  11111101
  254  11111110
  255  11111111
公式文書,認める that in this simplest binary, the biggest number you can show is 255, just as if my car only has 5 wheels on it's odometer, no 事柄 how far I 運動 it, at worst it will only ever show that I've been 99,999 miles.

Now.. to 変える from binary to decimal: The "secret" is to know that the columns have values. The 権利 手渡す-most column is 価値(がある) 1. The next to the left is 価値(がある) 2, the next 4, the next 8, and so on: 16, 32, 64, 128.

You use the column value (警察などへの)密告,告訴(状) as follows:
binary 1000 would be 同等(の) to 8 (4th column's 価値(がある):8)
binary 1001 would be 同等(の) to 9 (1+8.. it is easiest to work from 権利 to left)
binary 1011 would be 同等(の) to 11 (1+2+8)
変えるing from decimal to this simple binary isn't something I often need to do, but it can be done. That 過程 is best done from left to 権利: If you 手配中の,お尋ね者 the binary for 67, you would proceed as follows...

83 must be shown by 1xxxxxx, by which I mean "a 1 in the 7th column from the 権利, and as-yet-to-be-決定するd 1s and 0s in the other columns. Any simple binary number with a 1 in the 7th column is 価値(がある) 64 加える something, 予定 to the value of the 7th column. 83 is 19 more than 64, so the other 1s and 0s must be 価値(がある) 19. There would be a 0 in the 6th column, because, after accounting for 64 with the first 1, there's no 32 to account for. So our answer so far is 10xxxxx. Putting a 1 in the 5th column from the 権利 accounts for another 16, so there's 3 left to account for. Answer so far: 101xxxx. With only 3 left to account for, we put 0s in the "8" and "4" columns. Answer so far: 10100xx. A 1 in the second column is 価値(がある) 2, leaving one to be accounted for, and, not coincidentally the remaining column is 価値(がある) 1. Final answer: 1010011.


I keep talking about "simple" binary. ANY code using only 1s and 0s is a binary code. Any number made of 1s and 0s is a binary number. As long as the writer and the reader are agreed on what system is to be used, all is 井戸/弁護士席. I'm going to talk for a while about other codes which are useful in some circumstances. その上の 負かす/撃墜する the page (after the next 水平の line) I'm going to talk about bitwise 操作/手術s... something else you do with numbers in computers.

Suppose you want to 蓄える/店 serial numbers from 0 to 9999 in the computer. One 計画/陰謀 that might be used is binary coded decimal, BCD. For this, you'd use two bytes per serial number. Each byte would be looked at in two halves. (4 bits is called a nibble... really!) To code 1234 in this 計画/陰謀, you'd 蓄える/店 0001 0010 0011 0100. There are disadvantages to BCD, but it does have the advantage of 存在 平易な to work with after just a little getting used to it.

If you have 原因(となる) to do much work with binary numbers, you soon learn another notation, called hex. Hex is a little like BCD. You still look at the byte in two nibbles, however, you 許す ANY combination in each half. Some hex numbers are the same as the BCD 同等(の), e.g.:
Binary: 00000010  00100011 10011001
Hex:       02        23       99
What do you do, though, when then nibble is 同等(の) to decimal 10? In that 事例/患者, you 令状 an A, and so on:
Binary Decimal Hex
 1010    10     A
 1011    11     B
 1100    12     C
 1101    13     D
 1110    14     E
 1111    15     F
Once you've agreed this, you can 令状 any byte with just two characters, e.g. 11111111 is FF.

There are ways to say whether 11 should be 扱う/治療するd as a decimal 11, a binary 11 (same as 3 in decimal), or as hex 11 (same as 17 in decimal.) If you have subscripts, you suffix 10, 2 or 16 それぞれ. Putting an H or a $ in 前線 of, say, 11, e.g. $11 usually signifies you mean hex 11. A B or % is used to denote binary.

When working with numbers in the computer, it is ありふれた to 含む 主要な 無s. While we would rarely 令状 025 in everyday life, it isn't 半端物 to 令状 00010001 when 取引,協定ing with numbers for the computer. It makes (疑いを)晴らす that no digits have been left out by mistake. 海軍の helmsmen would never say they were steering a course of 25; they'd call it 無 two five, to make (疑いを)晴らす that they hadn't failed to hear, say, one two five.

What about 消極的な numbers? If you use the leftmost bit in the byte to 伝える 調印する, 00000001 could be 肯定的な 1 and 10000001 could be 消極的な one. Something a bit like this is 一般的に used... but with a 新たな展開 there isn't time to go into here. The system is called "two's complement arithmetic" if you want to look it up どこかよそで.

Numbers with a わずかの part get even more exciting. 基本的に, you have to 貿易(する) off three things (besides 複雑さ). You can strike many 妥協s between...
The number of bytes needed to 蓄える/店 the number
The biggest number you can show (no system has no 限界.)
The 正確 you can 達成する.
We'll only look at the last of those, and that only 簡潔に. If you said "I need to be able to show 0 to 255,000, but only to the nearest 1,000", I'd say to you: Put the number of thousands in a byte. 00000001 would mean 1,000. 11111111 (255 in simple decimal) would mean 255,000. Problem solved... but at a price.

And so far we've only done codes for showing numbers with 1s and 0s!

qTO DO: ASCII, EXOTICS.


Bitwise 操作/手術s.

Suppose you had a computer controlling the heating in a mansion. Suppose the heat to each room could be turned on or off 分かれて. You might have a computer program in 告発(する),告訴(する)/料金. that program might 蓄える/店 the 現在の setting of each room in a separate variable... a variable using up 8 bits of the computers memory.... OR you might get clever, and "code" the ons and offs into a 選び出す/独身 byte of memory. For the home heating example, the saving would be too small to be 価値(がある) the hassle, but 類似の tricks are worthwhile in other 状況/情勢s.

So.. now instead of the left 手渡す most column of the byte 存在 価値(がある) 128, as it would be in a simple binary code, the bit there might stand for sitting room heat on (if 1) or off (if 無). the next column could 示す the 明言する/公表する 要求するd in the kitchen, the next byte the bedroom, etc.

How are we going to work with individual bits out of the byte?

You may have read どこかよそで in this tutorial of the AND, OR, and XOR 操作/手術s. どこかよそで I've written about them as Boolean 操作者s, and all i said was true. However, they can also be 適用するd as follows:

If you AND the に引き続いて binary numbers together, you get the result shown. 公式文書,認める I am (正確に!) using the word "AND" as a verb. It doesn't have to be 出資するd to keep Pascal happy, but I will do that here to distinguish this use from ANDs everyday use.
110011  First number
111000  Second number
110000  First AND Second answer
You only need to know that when ANDing numbers, you work on each column 分かれて. You also need to know that the answer to (1 AND 1) is 1, but (0 AND 1), or (1 AND 0), or (0 AND 0) all equal 0. The answer is 1 only when the first AND the second bit going into the answer are 1s.

Because that last paragraph is hard to read, the に引き続いて way of showing such things was invented. It is called a truth (米)棚上げする/(英)提議する.
AND:   A
     0   1
    -------
 0 | 0   0
B  |
 1 | 0   1
"A" and "B" are the inputs, i.e. the bits 存在 ANDed together. Each can be a 1 or a 0. You just look at the 関連した 交差点 in the grid to find out the answer to any particular combination of 1s and 0s in A and B

Give this a try, be sure you can see that the answer is 権利:
100011  First number
110110  Second number
100010  First AND Second answer
The OR 支配する 作品 as follows:
OR:    A
     0   1
    -------
 0 | 0   1
B  |
 1 | 1   1

And the other important 支配する, the XOR 支配する, 作品 as follows:

XOR:   A
     0   1
    -------
 0 | 0   1
B  |
 1 | 1   0
Now that we have those 道具s, I can show you how to change the bit which codes for the heat in, say, the kitchen to be on. Remember: The kitchen was coded with the bit in the 7th column. (A little aside for you: That's often called column 6, as the 権利 手渡す column is often called column 無.)

早期に in your program, in the part 遂行する/発効させるd only once, you would 始める,決める up something called mKitchenOn. "m" for "mask", which is 存在 used here in the sense of "stencil". In mKitchenOn, you would 蓄える/店 01000000. (You could also use a constant, if you know about them. Best way to go for this.)

Assume you are 蓄える/店ing the 明言する/公表する for the heating in a variable called bHeat. All you need to do to turn the heat on is....

Pascal 見解/翻訳/版....
bHeat:=bHeat OR mKitchenOn;
Arduino (C) 見解/翻訳/版...
TO BE DONE STILL...
令状ing X's for bits who's 明言する/公表する we don't need to know about for the 狭くする question of whether what I've said will work will work, we can 分析する my 提案 as follows
xxxxxxxx  bHeat before OR 操作/手術
01000000  mKitchenOn

x1xxxxxx  result of OR 操作/手術.
No 事柄 what the 7th column bit was in bHeat, after ORing with the 1 in mKitchenOn, it will be a 1. All the other bits will be as they were before. Either you ORd a 1 with a 0, leaving the 1 you started with, or you ORd a 0 with a 0, leaving the 0 you started with. 冷静な/正味の?!

What if you want to make the bit a 0? 始める,決める up a mask mKitchenOff which is 10111111, and do

Pascal 見解/翻訳/版....
bHeat:=bHeat AND mKitchenOff;
Arduino (C) 見解/翻訳/版...
TO BE DONE STILL...
You can check this the same way as we checked the ORing
xxxxxxxx  bHeat before AND 操作/手術
10111111  mKitchenOff

x0xxxxxx  result of OR 操作/手術.


How can we see whether the bit in the 7th column is a 1 or a 0, 関わりなく what the other bits are? The に引き続いて does the 職業, even if the 指名する for the mask may 誤って導く in this use.

Pascal 見解/翻訳/版....
if (bHeat AND mKitchenOn) = 0 then begin
     {Kitchen bit was 0}
     DoWhatYouLike;
     end
   else begin
     {Kitchen bit was 1}
     DoTheOtherThing;
     end
Arduino (C) 見解/翻訳/版...
TO BE DONE STILL...


That's all for now!


To search THIS 場所/位置.... (Go to the 場所/位置's above, and use their search buttons if you want to search them.)... Way to search this 場所/位置 without using forms
Search this 場所/位置 or the web 力/強力にするd by FreeFind

場所/位置 search Web search

広告 from page's editor: Yes.. I do enjoy 収集するing these things for you... hope they are helpful. However.. this doesn't 支払う/賃金 my 法案s!!! If you find this stuff useful, (and you run an MS-DOS or Windows PC ) please visit my freeware and shareware page, download something, and 循環させる it for me? Links on your page to this page would also be 高く評価する/(相場などが)上がるd!
Click here to visit editor's freeware, shareware page.

Link to editor's (Arunet) homepage
How to email or 令状 this page's editor, Tom Boyd