Didactic Bytes
-
- Posts: 20
- Joined: Tue Apr 13, 2010 7:48 am
- Location: Makassar, ID
Re: Didactic Bytes
what r u talking about??TMBest wrote:199*256*256+77*256+202
hex consist only 00 - FF = 0 - 255, so it means there's no 256
No Pain = Gain
That's how programmer develops...
That's how programmer develops...
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
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
-
- Posts: 20
- Joined: Tue Apr 13, 2010 7:48 am
- Location: Makassar, ID
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')
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')
No Pain = Gain
That's how programmer develops...
That's how programmer develops...
-
- Posts: 20
- Joined: Tue Apr 13, 2010 7:48 am
- Location: Makassar, ID
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...
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...
No Pain = Gain
That's how programmer develops...
That's how programmer develops...
-
- Posts: 20
- Joined: Tue Apr 13, 2010 7:48 am
- Location: Makassar, ID
-
- Posts: 3
- Joined: Wed May 02, 2012 7:50 pm
Python:
Code: Select all
int(''.join("%08d"%int(bin(i)[2:]) for i in [199, 77, 202]),2)
255 character limit for signatures. Almost enough to display each ASCII character exactly twice (if all characters printed). One less than enough to display every character in ANSI exactly once (again, if all printed). Also, the number of characters here.
Convert each number from decimal to binary using "calc.exe":
Append a 0 at the beginning of 77's binary value.
Concat the 3 values => 110001110100110111001010
Convert binary to decimal => 13061578
Python:
=> 13061578
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)