Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (777)
Games in Android Showcase (231)
games submitted by our members
Games in WIP (856)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [solved] Do you need all bits to represent a byte?  (Read 2090 times)
0 Members and 1 Guest are viewing this topic.
Offline Ecumene

JGO Kernel


Medals: 197
Projects: 4
Exp: 8 years


I did not hit her! I did not!


« Posted 2014-09-08 03:28:54 »

In my "computer technology" class, they're teaching us basic binary.

I keep seeing this:
000001112
being:
1112

I understand that if you wanted to write a byte "101" and "111" together it would be
000001012 000001112

My question is, can you write a byte without having the 0s before the actual "useful" part? Or does it mean something else?

(Excuse me if I'm wrong on something, the only teacher I met was a substitute and only taught us the basics, not binary math or anything. In fact, he sometimes wrote it with all the bits, and sometimes just 4 or five. He was kind of inconsistent...)

Offline BurntPizza

« JGO Bitwise Duke »


Medals: 486
Exp: 7 years



« Reply #1 - Posted 2014-09-08 03:32:55 »

Can you write 014 and still mean 14?

Yes.
Technically you can have any number of leading zeros in any base, and it doesn't affect the number.

However, note that if the number is in two's complement (aka signed) then the most significant bit does matter, it's the sign bit. This is because binary doesn't have a negative sign (can't write -014). But one's complement, the zeros don't matter.

EDIT: actually, not sure on that terminology, I should say that the zeros don't matter with unsigned integers, too sleepy to go verify on one's complement etc.
Offline nerb
« Reply #2 - Posted 2014-09-08 03:43:11 »

I'd say no, because a byte implies a word length (8 in general). You can write binary/bits 111, but that's not a byte.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Ecumene

JGO Kernel


Medals: 197
Projects: 4
Exp: 8 years


I did not hit her! I did not!


« Reply #3 - Posted 2014-09-08 03:45:38 »

I'd say no, because a byte implies a word length (8 in general). You can write binary/bits 111, but that's not a byte.

My bad, I meant would 1012 in a byte represent 000001012 or something else. Thanks anyway!

Offline Roquen

JGO Kernel


Medals: 518



« Reply #4 - Posted 2014-09-08 07:29:47 »

It depends.  What do the three bits represent?  Yes that's it for unsigned.   And it's 111111012 in signed 2's complement.

Quote
word length (8 in general)
Typically a word will refer to the native bit size of a register.  But not so clear with modern 64-bit CPUs.
Offline richierich
« Reply #5 - Posted 2014-09-08 07:56:43 »

My question is, can you write a byte without having the 0s before the actual "useful" part?

Wall of text to clarify ambiguous terminology, sorry ... Smiley

A byte just means a group of 8 bits (binary digits). It isn't necessarily a number - it's a good idea to get the two things separate in your mind. Bytes are commonly used for other things as well as representing numbers. E.g. as well as the numbers from 0 to 255 a byte might hold 256 unique combos of bits for 256 distinct enemy types, or the 8 bits can be used individually for 8 boolean (i.e. true or false) flags.

Just like decimal digits need not represent numbers. E.g. a group of 4 like "1234" could be a ATM code, or a group of 6 like "555123" a local phone.

So in answer to your literal question, no you can't really write a byte without leading zeros because a byte actually means 8 bits. If you wrote 4 it would be a "nybble" (terrible word!) But to answer the question you may have meant, see BurntPizza above. Leading zeros are not meaningful when writing a number in any base for a human to read.

I can remember when I was taught binary it took me a while to separate the two subjects in my head of
(a) binary numbers in general as a math concept, and
(b) how computers use their little chunks of bits and bytes to perform binary arithmetic.
I guess it's natural to teach them together because binary math isn't used anywhere else except in computers, but I remember finding it confusing for a while till I got it clear they are distinct.

Quote from: BurntPizza
However, note that if the number is in two's complement (aka signed) then the most significant bit does matter, it's the sign bit.

So to be clear, talking of twos-complement is part of subject (b) ... i.e. it's how a computer represents negative numbers using only "1"s and "0"s. In human written language ... i.e. subject (a) ... something like "minus 15", i.e decimal -15 would be written in binary as -1111. When the class looks into subject (b) in more detail they'll come across not only twos-complement as a way of representing negatives, but the beauties of endianism too. I envy you, lucky students Grin

Pages: [1]
  ignore  |  Print  
 
 

 
hadezbladez (349 views)
2018-11-16 13:46:03

hadezbladez (183 views)
2018-11-16 13:41:33

hadezbladez (348 views)
2018-11-16 13:35:35

hadezbladez (84 views)
2018-11-16 13:32:03

EgonOlsen (2179 views)
2018-06-10 19:43:48

EgonOlsen (2221 views)
2018-06-10 19:43:44

EgonOlsen (1378 views)
2018-06-10 19:43:20

DesertCoockie (2011 views)
2018-05-13 18:23:11

nelsongames (1668 views)
2018-04-24 18:15:36

nelsongames (2308 views)
2018-04-24 18:14:32
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!