byte questions
Rontopia
Posts: 139
hi all
Im working with a BS2 and as we all know there are 32 bytes of ram for var's
my question is about the definition of byte as 0 to 255.. does this mean that a bite can be -128 to + 128.. or 127. Or does a byte have to be 0 to 255?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Muahdib
IC layout designer
Phoenix Arizona
Im working with a BS2 and as we all know there are 32 bytes of ram for var's
my question is about the definition of byte as 0 to 255.. does this mean that a bite can be -128 to + 128.. or 127. Or does a byte have to be 0 to 255?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Muahdib
IC layout designer
Phoenix Arizona
Comments
thanks
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Muahdib
IC layout designer
Phoenix Arizona
A Byte can only be an integer value from 0 to 255.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Randy
while I dont understand the hexadecimal stuff.. I understand that it must be an integer between 0 to 255 or 2 to the power of 8.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Muahdib
IC layout designer
Phoenix Arizona
Adventures in Binary Math
Like the decimal system the binary system can have negative or positive numbers depending whether you use the highest bit as a negative sign. Either way the math works the same.·
When you add in binary you carry the bit when the answer is greater than 1.· You also borrow the bit when the answer is less than zero. So it looks like this:
subtraction
···· 00000000··· zero
··· -00000001··· minus one
···· 11111111····equals negative one - note that the highest bit is on.
addition
···· 11111110·· negative two
··· +00000011· plus three
···· 00000001·· equals 1
Actually it equals 100000001 (decimal 257) but since a byte has only 8 bits you loose the ninth (left) bit and Eureka!!!! you got the right answer.
Please Note: If the memory was addressed as a WORD (16 bits)·the ninth bit·would not be imaginary. Working with an imaginary bit is·an overflow if it yields the wrong result.
The easiest way to convert an unsigned byte to a signed byte is to look if the sign bit is "on" and if it is subtract the value from 256.
Multiplication and division follow the same rules as in the decimal world and floating point math is the·ultimate methodology for higher mathematics.· But before you try to "normalize" a number·try doing some research.
I'm only scratching the surface of binary math, a subject that is way beyond the scope of this "post",·so I would suggest buying a good book on the subject.
Here's the list of· values for a byte.
Byte Values:
Binary··· unsigned signed
00000000······ 0············ 0
00000001······ 1············ 1
00000010······ 2············ 2
00000011······ 3············ 3
00000100······ 4············ 4
00000101······ 5············ 5
00000110······ 6············ 6
00000111······ 7············ 7
00001000······ 8············ 8
00001001······ 9············ 9
00001010······ 10··········· 10
00001011······ 11··········· 11
00001100······ 12··········· 12
00001101······ 13··········· 13
00001110······ 14··········· 14
00001111······ 15··········· 15
00010000······ 16··········· 16
00010001······ 17··········· 17
00010010······ 18··········· 18
00010011······ 19··········· 19
00010100······ 20··········· 20
00010101······ 21··········· 21
00010110······ 22··········· 22
00010111······ 23··········· 23
00011000······ 24··········· 24
00011001······ 25··········· 25
00011010······ 26··········· 26
00011011······ 27··········· 27
00011100······ 28··········· 28
00011101······ 29··········· 29
00011110······ 30··········· 30
00011111······ 31··········· 31
00100000······ 32··········· 32
00100001······ 33··········· 33
00100010······ 34··········· 34
00100011······ 35··········· 35
00100100······ 36··········· 36
00100101······ 37··········· 37
00100110······ 38··········· 38
00100111······ 39··········· 39
00101000······ 40··········· 40
00101001······ 41··········· 41
00101010······ 42··········· 42
00101011······ 43··········· 43
00101100······ 44··········· 44
00101101······ 45··········· 45
00101110······ 46··········· 46
00101111······ 47··········· 47
00110000······ 48··········· 48
00110001······ 49··········· 49
00110010······ 50··········· 50
00110011······ 51··········· 51
00110100······ 52··········· 52
00110101······ 53··········· 53
00110110······ 54··········· 54
00110111······ 55··········· 55
00111000······ 56··········· 56
00111001······ 57··········· 57
00111010······ 58··········· 58
00111011······ 59··········· 59
00111100······ 60··········· 60
00111101······ 61··········· 61
00111110······ 62··········· 62
00111111······ 63··········· 63
01000000······ 64··········· 64
01000001······ 65··········· 65
01000010······ 66··········· 66
01000011······ 67··········· 67
01000100······ 68··········· 68
01000101······ 69··········· 69
01000110······ 70··········· 70
01000111······ 71··········· 71
01001000······ 72··········· 72
01001001······ 73··········· 73
01001010······ 74··········· 74
01001011······ 75··········· 75
01001100······ 76··········· 76
01001101······ 77··········· 77
01001110······ 78··········· 78
01001111······ 79··········· 79
01010000······ 80··········· 80
01010001······ 81··········· 81
01010010······ 82··········· 82
01010011······ 83··········· 83
01010100······ 84··········· 84
01010101······ 85··········· 85
01010110······ 86··········· 86
01010111······ 87··········· 87
01011000······ 88··········· 88
01011001······ 89··········· 89
01011010······ 90··········· 90
01011011······ 91··········· 91
01011100······ 92··········· 92
01011101······ 93··········· 93
01011110······ 94··········· 94
01011111······ 95··········· 95
01100000······ 96··········· 96
01100001······ 97··········· 97
01100010······ 98··········· 98
01100011······ 99··········· 99
01100100······ 100·········· 100
01100101······ 101·········· 101
01100110······ 102·········· 102
01100111······ 103·········· 103
01101000······ 104·········· 104
01101001······ 105·········· 105
01101010······ 106·········· 106
01101011······ 107·········· 107
01101100······ 108·········· 108
01101101······ 109·········· 109
01101110······ 110·········· 110
01101111······ 111·········· 111
01110000······ 112·········· 112
01110001······ 113·········· 113
01110010······ 114·········· 114
01110011······ 115·········· 115
01110100······ 116·········· 116
01110101······ 117·········· 117
01110110······ 118·········· 118
01110111······ 119·········· 119
01111000······ 120·········· 120
01111001······ 121·········· 121
01111010······ 122·········· 122
01111011······ 123·········· 123
01111100······ 124·········· 124
01111101······ 125·········· 125
01111110······ 126·········· 126
01111111······ 127·········· 127
10000000······ 128········· - 128
10000001······ 129········· - 127
10000010······ 130········· - 126
10000011······ 131········· - 125
10000100······ 132········· - 124
10000101······ 133········· - 123
10000110······ 134········· - 122
10000111······ 135········· - 121
10001000······ 136········· - 120
10001001······ 137········· - 119
10001010······ 138········· - 118
10001011······ 139········· - 117
10001100······ 140········· - 116
10001101······ 141········· - 115
10001110······ 142········· - 114
10001111······ 143········· - 113
10010000······ 144········· - 112
10010001······ 145········· - 111
10010010······ 146········· - 110
10010011······ 147········· - 109
10010100······ 148········· - 108
10010101······ 149········· - 107
10010110······ 150········· - 106
10010111······ 151········· - 105
10011000······ 152········· - 104
10011001······ 153········· - 103
10011010······ 154········· - 102
10011011······ 155········· - 101
10011100······ 156········· - 100
10011101······ 157········· - 99
10011110······ 158········· - 98
10011111······ 159········· - 97
10100000······ 160········· - 96
10100001······ 161········· - 95
10100010······ 162········· - 94
10100011······ 163········· - 93
10100100······ 164········· - 92
10100101······ 165········· - 91
10100110······ 166········· - 90
10100111······ 167········· - 89
10101000······ 168········· - 88
10101001······ 169········· - 87
10101010······ 170········· - 86
10101011······ 171········· - 85
10101100······ 172········· - 84
10101101······ 173········· - 83
10101110······ 174········· - 82
10101111······ 175········· - 81
10110000······ 176········· - 80
10110001······ 177········· - 79
10110010······ 178········· - 78
10110011······ 179········· - 77
10110100······ 180········· - 76
10110101······ 181········· - 75
10110110······ 182········· - 74
10110111······ 183········· - 73
10111000······ 184········· - 72
10111001······ 185········· - 71
10111010······ 186········· - 70
10111011······ 187········· - 69
10111100······ 188········· - 68
10111101······ 189········· - 67
10111110······ 190········· - 66
10111111······ 191········· - 65
11000000······ 192········· - 64
11000001······ 193········· - 63
11000010······ 194········· - 62
11000011······ 195········· - 61
11000100······ 196········· - 60
11000101······ 197········· - 59
11000110······ 198········· - 58
11000111······ 199········· - 57
11001000······ 200········· - 56
11001001······ 201········· - 55
11001010······ 202········· - 54
11001011······ 203········· - 53
11001100······ 204········· - 52
11001101······ 205········· - 51
11001110······ 206········· - 50
11001111······ 207········· - 49
11010000······ 208········· - 48
11010001······ 209········· - 47
11010010······ 210········· - 46
11010011······ 211········· - 45
11010100······ 212········· - 44
11010101······ 213········· - 43
11010110······ 214········· - 42
11010111······ 215········· - 41
11011000······ 216········· - 40
11011001······ 217········· - 39
11011010······ 218········· - 38
11011011······ 219········· - 37
11011100······ 220········· - 36
11011101······ 221········· - 35
11011110······ 222········· - 34
11011111······ 223········· - 33
11100000······ 224········· - 32
11100001······ 225········· - 31
11100010······ 226········· - 30
11100011······ 227········· - 29
11100100······ 228········· - 28
11100101······ 229········· - 27
11100110······ 230········· - 26
11100111······ 231········· - 25
11101000······ 232········· - 24
11101001······ 233········· - 23
11101010······ 234········· - 22
11101011······ 235········· - 21
11101100······ 236········· - 20
11101101······ 237········· - 19
11101110······ 238········· - 18
11101111······ 239········· - 17
11110000······ 240········· - 16
11110001······ 241········· - 15
11110010······ 242········· - 14
11110011······ 243········· - 13
11110100······ 244········· - 12
11110101······ 245········· - 11
11110110······ 246········· - 10
11110111······ 247········· - 9
11111000······ 248········· - 8
11111001······ 249········· - 7
11111010······ 250········· - 6
11111011······ 251········· - 5
11111100······ 252········· - 4
11111101······ 253········· - 3
11111110······ 254········· - 2
11111111······ 255········· - 1
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
TR