Advertisement

Bits and bytes - and Bitwise Logical Operators ??!

Started by August 20, 2001 08:20 AM
3 comments, last by Destroyer 23 years, 6 months ago
Hi, I''m posting this because this is a MAJOR language feature especially when dealing with game programming that I don''t understand one bit - and I haven''t found a good reference for - yet... So I''m asking for someone''s help, or someone directing me to a good site, but here are some of my questions that have to deal with those bits and bytes... What is a "Hi Word" and a "Lo Word" (Low Word) Why is a Word a 16 bit value and a DWord a 32 bit value ? What''s a high bit and a low bit ? What''s the sign bit? Do you read binary left to right - or right to left? What do all the Bitwise Logical Operators do ? ( &, |, ~, etc...) | L-> In english please Each hexcidecimal notation is 4 bits right ? e.g 0xF - 4 bits (1111) Anyway - it feels great giving off that chest - and I would really like some help (as you can so planly see) Any directions or help to any of these questions would greatly be appreciated - and yes - I don''t know how I got through programming games without it Thanks, Destroyer
word = 16 bits
dword = double word (32 bits)
loword = low word from a dword (16 bits)
hiword = high word from a dword (16 bits)
qword = quad word (64 bits)

The high bit is simply the most significant bit of any bit of a piece of data, so the high bit of a 16 bit word would be bit 16. The low bit is the least significant, ie bit 0.

Binary is normally written with the least significant bit on the left, so....

1000 = 8
0100 = 4
0010 = 2
0001 = 1

of course you normally dont bother writing the leading zeroes.

The bitwise operators perform logic ops on individual bits. eg

(OR) 0100 | 0110 = 0110
(AND) 0100 & 0110 = 0100
(XOR) 0100 ^ 0110 = 0010

the ~ operator inverts the bits...

~0110 = 1001
~0100 = 1011

the shift operators shift the bit pattern up or down

0110 << 1 = 1100
0100 >> 2 = 0001

Finally, yes, a hex digit represents 4 bits (or a nybble - half a byte)

[edit]
oops, missed one...the sign bit is the bit that tells you what sign a number is. If it is set high, the number is negative, if it is low, the number is positive. It is usually the top bit of a signed number. Note that you cant just flip the bit to make a number (eg 8) into a negative number (-8) - you have to use twos complement arithmetic to do the conversion. If you just flip the bit, 8 becomes -120.
To convert x to -x, use this...

(~x)+1;

eg 8...

~00001000 = 11110111
11110111 + 1 = 11111000 = -8

43...

~00101011 = 11010100
11010100 + 1 = 11010101 = -43

Hope this clears things up a bit


Edited by - Sandman on August 20, 2001 10:48:34 AM
Advertisement
Hi,

Thanks !

That''s helps a lot - I had to work through the Bitwise Logical Operators (&AND, |OR, and ^XOR) but I got it with a little help from a logic book called "The Logic Book" it contains stuff like that in there... I finally get it !

Only 1 question remains...

What''s two''s compliment arithmetic ?

Thanks a LOT!

Destroyer
Hi,

Thanks !

That helps a lot - I had to work through the Bitwise Logical Operators (&AND, |OR, and ^XOR) but I got it with a little help from a logic book called "The Logic Book". It contains stuff like that in there (Exclusive OR)... I finally get it !

Only 1 question remains...

What''s two''s compliment arithmetic ?

Thanks a LOT!

Destroyer
http://qsoft.ragestorm.com/tutors/dos/bytes.html

Arkon
[QSoft Systems]

This topic is closed to new replies.

Advertisement