Page 1 of 1
Didactic Bytes
Posted: Thu Aug 20, 2009 1:58 am
by TMBest
199*256*256+77*256+202
Re: Didactic Bytes
Posted: Thu Apr 15, 2010 5:46 am
by TechnoDemon
TMBest wrote:199*256*256+77*256+202
what r u talking about??
hex consist only 00 - FF = 0 - 255, so it means there's no 256
Posted: Thu Apr 15, 2010 6:47 am
by CodeX
There's 256 values you can store though, 1-255 is 255 values and 0 is one more so you have 256. Some abstract number theory:
largest value representable: r^d-1
number of values representable: r^d
where r is the radix/root/base (i.e. 2) and d is the number of digits (i.e.
so for a binary byte:
2^8-1 = 255
2^8 = 256
just as with decimal you have
10^3-1 = 999
10^3 = 1000
also looking at the post it looks like TMBest is creating a 3 byte value
0xc74dca
go figure
Posted: Thu Apr 15, 2010 2:23 pm
by TechnoDemon
from what TMBest wrote, there are several possible results coz he wrote no brackets, i couldn't figure which op to execute first:
199*256*256+77*256+202
=> (199*256) * (256+77) * (256+202)
=> 50944 * 333 * 458
=> 7769673216
is different if brackets move one step to the right:
=> 199 * (256*256) + (77*256) + 202
=> 199 * 65536 + 19712 + 202 'even this can result more possibilities (vb mode = ON)
=> if (199 * 65536) + 19712 + 202 = 13041664 + 19914 = 13061578
=> else 199 * (65536+19712+202) = 199 * 85450 = 17004550
and other possibilities.
CONFUSED ::sighs::
even processor will be confused if there's no operation's priority (i mean 'brackets')
Posted: Fri Apr 16, 2010 12:41 am
by CodeX
... did you ever go to
school?
Posted: Fri Apr 16, 2010 6:49 am
by TechnoDemon
oh...
my bad...
I forgot that multiply op is cumulative ( (a*b)*c=a*(b*c) )
this hacker.org's challenges makes me think to complicated.
Btw, thx for the advise, but i'm an university student and almost got my S.E (Sarjana Ekonomi = Bachelor of Economy in Indonesia). I appreciate it...
Posted: Fri Apr 16, 2010 7:00 am
by CodeX
I can see why there's a global recession
Posted: Fri Apr 16, 2010 7:48 am
by Karian
TechnoDemon wrote:I forgot that multiply op is cumulative ( (a*b)*c=a*(b*c) )
I guess you mean it is associative?
Posted: Sat Apr 17, 2010 12:50 pm
by TechnoDemon
@CodeX
hahahaha... just forget about it, it's a shame
@Karian
that's what i mean... forgive my poor english...
Posted: Wed May 02, 2012 8:21 pm
by DragonEgghead
Python:
Code: Select all
int(''.join("%08d"%int(bin(i)[2:]) for i in [199, 77, 202]),2)
Posted: Fri May 04, 2012 11:48 am
by lortedy
Convert each number from decimal to binary using "calc.exe":
Code: Select all
199 = 11000111
77 = 1001101
202 = 11001010
Append a 0 at the beginning of 77's binary value.
Concat the 3 values => 110001110100110111001010
Convert binary to decimal => 13061578
Python:
Code: Select all
def binary2decimal(binaryNumber):
multiplier = 0
number = 0
for el in binaryNumber[::-1 ]:
number += int( el ) * ( 2**multiplier )
multiplier += 1
return number
def decimal2binary(decimalNumber):
bStr = ''
if decimalNumber < 0: raise ValueError, "Must be a positive integer."
if decimalNumber == 0: return '0'
while decimalNumber > 0:
bStr = str(decimalNumber % 2) + bStr
decimalNumber = decimalNumber >> 1
return bStr
a, b, c = 199, 77, 202
a, b, c = decimal2binary(a), decimal2binary(b), decimal2binary(c)
b = '0'+b # Add a leading 0 to binary value of 77 as it has only 7 bits (not a complete byte)
val = ''
val = a+b+c
print binary2decimal(val)
=> 13061578