Radio Shack Mobile Robot manual Hexadecimal, Binary, Bytes, Words, etc

Models: Mobile Robot

1 54
Download 54 pages 35.2 Kb
Page 38
Image 38

Hexadecimal, Binary, Bytes, Words, etc.

Most commands require parameters in the form of hexadecimal values and many commands return hexadecimal values. Sometimes the bits in these values will represent certain things. We’ll use the term “hex” to refer to hexadecimal.

Hexadecimal

Hex numbers are easy for computers to work with because each hex digit can represent 4 bits, 2 hex dig- its can represent a byte, and 4 hex digits can represent a word. Sometimes hex digits are referred to as nibbles. Hex numbers are base 16 instead of base 10 like our decimal numbering system. Hex digits are: 0 1 2 3 4 5 6 7 8 9 A B C D E F (16 total).

Bits

A bit is a single binary (base 2) digit which can be a “1” or a “0“. Digital computers such as the Basic Stamp, use binary values for processing. A “1” is ON or HIGH, a “0” is OFF or LOW.

Bytes

A byte consists of 8 bits. A byte can be represented as a hex value such as “00” or “FF“. The range of values that a byte can represent is 0-255 decimal (00-FF hex).

Words

A word consists of 2 bytes (16 bits). A word can be represented as a hex value such as “0000” or “FFFF“. The range of values that a word can represent is 0-65535 decimal (0000-FFFF hex).

The following table shows the binary equivalent for each hex digit:

Hex digit

Binary value (bits)

Decimal

0

0000

0

1

0001

1

2

0010

2

3

0011

3

4

0100

4

5

0101

5

6

0110

6

7

0111

7

Hex digit

Binary value (bits)

Decimal

8

1000

8

9

1001

9

A

1010

10

B

1011

11

C

1100

12

D

1101

13

E

1110

14

F

1111

15

Basic Stamp Commands

The Basic Stamp II’s PBasic language has special commands used to convert numbers to hexadecimal as needed by the coprocessor. See the SERIN and SEROUT commands in the Basic Stamp Program- ming manual for details (available at the Parallax web site http://www.parallaxinc.com). Examples:

serout net,baud,["!1R1", hex2 position] 'Move RC Servo Motor.

serin net,baud,[hex4, ec]

'Get encoder as 4-hex characters into ec.

35

Page 38
Image 38
Radio Shack Mobile Robot manual Hexadecimal, Binary, Bytes, Words, etc