*crys* Binary

Posts 1–7 of 7 · Page 1 of 1
*crys* Binary
I'm reading a book on asm, and it told me not to continue if I don't understand binary. I don't understand binary.

Can some complain to me in more depth?

I understand the 10110 is equal to :

1 x 2^4 = 16
0 x 2^3 = 0
1 x 2^2 = 4
1 x 2^1 = 2
0 x 2^0 = 0

^ = to the power of.
What defines those values in the center, if all we input it 10110?
If you mean what defines 101011 or whatever, that's what the BIOS/CPU does, if I'm not mistaken.

I'm not 100% if that is what you are asking, please refine. If you are talking about Base-2, it's because it's the easiest representation of On-Off, hence that's why we use Base-2.
I need to know how time find out what they mean, or equal. For instance, the example in the book says :
Take the binary number 10110:
1 x 2^4 = 16
0 x 2^3 = 0
1 x 2^2 = 4
1 x 2^1 = 2
0 x 2^0 = 0
Answer: 22
And I'm supposed to understand binary by looking at that. =/
Quote Originally Posted by Someguytwo View Post
I need to know how time find out what they mean, or equal. For instance, the example in the book says :


And I'm supposed to understand binary by looking at that. =/
So, what you are saying is you understand how binary works, but you don't fully understand it? That's all there is to it, 8 bits make a byte. That's why there is a 255 character limit in the ASCII code list, hence why the sum of (2^8 to 0) = 256. Then each byte is represented on screen as ASCII characters.

For example 101 equals:
1 x 2^2 = 4
0 x 2^1 = 0
1 x 2^0 = 1

The sum of them equals 5, so 101 equals 5.
Okay, I understand now. Thanks Arun.
The easiest way to understand binary is like this: the very rightmost number is worth 1, and then to the left of that, you multiply 1 by 2, that place is worth 2, etc

11 = 3
10 = 2
01 = -1 ( I think)

so think of it like this, take 1, and every number to the left of it, you multiply it by 2 every time, so you go 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, etc. Every number to the right of the one you're looking at is ALWAYS worth 1 value less than what you're looking at. I know I'm bad at explaining this, but it's how I understand it, so if you're looking at 10000, which is equal to 32, then the "0000" is 1+2+4+8+16, even though 0 represents off and 1 represents on.

I just realized this thread is a month old, but my post is educational, so gtfo and don't call me on a necro.
The biggest time you will use this is BITMASKS where you set a bit in a number to represent options.

lets take a byte:
Code:
00h 00000000b
now lets make a bunch of flags that we can use:
Code:
FLAG1 equ 1d
FLAG2 equ 2d
FLAG3 equ 4d
FLAG4 equ 8d
FLAG5 equ 16d
FLAG6 equ 32d
FLAG7 equ 64d
FLAG8 equ 128d
now in order to apply these flags we use "or"
Code:
.data
Flag db 0
.code
mov eax, FLAG    ;eax = 00000000b
or eax, FLAG1    ;eax = 00000001b
;00000000b eax
;00000001b FLAG1
or eax, FLAG3    ;eax = 00000101b
;00000001b eax
;00000100b FLAG3 cause 100b = 4d aka FLAG3
or eax, FLAG6    ;eax = 00100101b
;00000101b eax
;00100000b FLAG6 cause 00100000b = 32d aka FLAG6
as you see we can change the bit in a byte by changing the byte to binary and changing the number we "or" into binary then "or'ing" them together...


@Junior731:
01b = 1d not -1
negative numbers use the SIGN FLAG to determine if the number should be negative or not. dword -1 in programming= 0FFFFFFFFh and will not necessarily set the sign flag. the sign flag is used in math functions, not set on a per data section. (aka all data is positive unless your math made it negative then it is only negative if you use the sign flag to tell if it is.)
Posts 1–7 of 7 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

Talk with us