Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How can I print a number larger than 128?

0 views
Skip to first unread message

kun niu

unread,
Dec 8, 2007, 8:32:42 AM12/8/07
to
Dear all,
I'm new here.
I've got a number larger than 128.
I want to send it by socket.
I find that if print the number directly, I'll print the number in
ascii format.
So I'll have 3 separate numbers transmitted.
But I only want to transmit one byte.
How can I do so?

Thanks for any help.

Q...@domain.invalid

unread,
Dec 8, 2007, 10:16:57 AM12/8/07
to

kun niu <haon...@gmail.com> wrote in message-id: <23f658ee-76ed-4d2f...@d27g2000prf.googlegroups.com>

You can try developing a compression algo or else use one off the shelf.
Something that reduces the need for consecutive zeros or ones.
The one byte constraint is more than a bit limiting though.

gl;

smallpond

unread,
Dec 8, 2007, 11:08:36 AM12/8/07
to


You should be able to send binary data to a socket using
syswrite(SOCK,$data,$length);
See packtut for information about packing data in network
byte order.
--S

Doug Miller

unread,
Dec 8, 2007, 12:07:16 PM12/8/07
to
In article <Jzy6j.1032$bW.927@trnddc07>, Q...@domain.invalid wrote:
>
>kun niu <haon...@gmail.com> wrote in message-id:
> <23f658ee-76ed-4d2f...@d27g2000prf.googlegroups.com>
>
>>
>> Dear all,
>> I'm new here.
>> I've got a number larger than 128.
>> I want to send it by socket.
>> I find that if print the number directly, I'll print the number in
>> ascii format.
>> So I'll have 3 separate numbers transmitted.
>> But I only want to transmit one byte.
>> How can I do so?
>>
>> Thanks for any help.
>
>You can try developing a compression algo or else use one off the shelf.

Why would that be necessary?

>Something that reduces the need for consecutive zeros or ones.

Why would that be necessary?

>The one byte constraint is more than a bit limiting though.

Huh? One byte = 8 bits, which can hold values up to 2^8 - 1 = 255. All he
needs to do is send it in binary.

--
Regards,
Doug Miller (alphageek at milmac dot com)

It's time to throw all their damned tea in the harbor again.

Q...@domain.invalid

unread,
Dec 8, 2007, 2:33:41 PM12/8/07
to

spam...@milmac.com (Doug Miller) wrote in message-id: <6bA6j.5046$fl7....@newssvr22.news.prodigy.net>

>
> In article <Jzy6j.1032$bW.927@trnddc07>, Q...@domain.invalid wrote:
> >
> >kun niu <haon...@gmail.com> wrote in message-id:
> > <23f658ee-76ed-4d2f...@d27g2000prf.googlegroups.com>
> >
> >>
> >> Dear all,
> >> I'm new here.
> >> I've got a number larger than 128.
> >> I want to send it by socket.
> >> I find that if print the number directly, I'll print the number in
> >> ascii format.
> >> So I'll have 3 separate numbers transmitted.
> >> But I only want to transmit one byte.
> >> How can I do so?
> >>
> >> Thanks for any help.
> >
> >You can try developing a compression algo or else use one off the shelf.
>
> Why would that be necessary?
>
> >Something that reduces the need for consecutive zeros or ones.
>
> Why would that be necessary?
>
> >The one byte constraint is more than a bit limiting though.
>
> Huh? One byte = 8 bits, which can hold values up to 2^8 - 1 = 255. All he
> needs to do is send it in binary.
>

cause the OP says that he wishes to send _only one byte_


Martijn Lievaart

unread,
Dec 8, 2007, 3:33:20 PM12/8/07
to

So? 128 is binary 10000000 which fits nicely in one byte.

M4

John Bokma

unread,
Dec 8, 2007, 4:27:07 PM12/8/07
to
Martijn Lievaart <m...@rtij.nl.invlalid> wrote:

> So? 128 is binary 10000000 which fits nicely in one byte.

128 is not larger than 128, so that's not the problem.

Anyway, up to (and including) 255 fits in one byte. If the OP needs to fit
all numbers in [0..max] with max > 255 in a single byte the OP has a
problem :-). If the number of numbers is limited to max 256 different
ones, it's possible to encode each in a byte.

--
John

http://johnbokma.com/

Doug Miller

unread,
Dec 9, 2007, 5:25:59 PM12/9/07
to

And your point would be....?

255 > 128, last time I checked.

Martijn Lievaart

unread,
Dec 9, 2007, 6:08:18 PM12/9/07
to
On Sun, 09 Dec 2007 22:25:59 +0000, Doug Miller wrote:

>>> >The one byte constraint is more than a bit limiting though.
>>>
>>> Huh? One byte = 8 bits, which can hold values up to 2^8 - 1 = 255. All
>>> he needs to do is send it in binary.
>>>
>>>
>>cause the OP says that he wishes to send _only one byte_
>>
>>
> And your point would be....?
>
> 255 > 128, last time I checked.

Ah I see it now. The OP wants to send a number GREATER than 128. If that
number is < 256, one byte will do. Otherwise if < 384, just subtract 128
and send it in byte. Otherwise, without more information, it seems
impossible.

M4

Doug Miller

unread,
Dec 10, 2007, 6:47:21 AM12/10/07
to
In article <pan.2007.12...@rtij.nl.invlalid>, Martijn Lievaart <m...@rtij.nl.invlalid> wrote:
>On Sun, 09 Dec 2007 22:25:59 +0000, Doug Miller wrote:
>
>>>> >The one byte constraint is more than a bit limiting though.
>>>>
>>>> Huh? One byte = 8 bits, which can hold values up to 2^8 - 1 = 255. All
>>>> he needs to do is send it in binary.
>>>>
>>>>
>>>cause the OP says that he wishes to send _only one byte_
>>>
>>>
>> And your point would be....?
>>
>> 255 > 128, last time I checked.
>
>Ah I see it now. The OP wants to send a number GREATER than 128.

Wouldn't matter if he wanted to send a number less than 128. As long as it's
in the range 0..255, one byte is sufficient to express it. If it's out of that
range, it's not, and no compression algorithm is going to change that.

Q...@domain.invalid

unread,
Dec 10, 2007, 10:07:32 AM12/10/07
to

spam...@milmac.com (Doug Miller) wrote in message-id: <dH97j.76990$YL5....@newssvr29.news.prodigy.net>

>
> In article <pan.2007.12...@rtij.nl.invlalid>, Martijn Lievaart <m...@rtij.nl.invlalid> wrote:
> >On Sun, 09 Dec 2007 22:25:59 +0000, Doug Miller wrote:
> >
> >>>> >The one byte constraint is more than a bit limiting though.
> >>>>
> >>>> Huh? One byte = 8 bits, which can hold values up to 2^8 - 1 = 255. All
> >>>> he needs to do is send it in binary.
> >>>>
> >>>>
> >>>cause the OP says that he wishes to send _only one byte_
> >>>
> >>>
> >> And your point would be....?
> >>
> >> 255 > 128, last time I checked.
> >
> >Ah I see it now. The OP wants to send a number GREATER than 128.
>
> Wouldn't matter if he wanted to send a number less than 128. As long as it's
> in the range 0..255, one byte is sufficient to express it. If it's out of that
> range, it's not, and no compression algorithm is going to change that.
>

Clocking.

Assume for a moment that the sending software and receiving software both
have hardcoded a _timing_ mechanism (asynchronous transmission).

Now the sending client starts the timer by sending its first bit, lets say
it is a zero, the sender will now not send any more bits until the value
of the bit is to change (lets say 14 cycles).

The receiver should now have a number like this, although it has received
only 1 bit. (the initial bit and 14 repetitions of that bit.)

0000000 00000000

Now the sender sends the next bit to indicate a change from 0 to 1.
Perhaps this time the sends waits 2 cycles after sending.

The reciever should now have a number like this, and we have sent
only 2 bits so far.

11 10000000 00000000

Some ethernet encodings work in a similar fashion to this.

Many more ways to do this.. gl

TonyV

unread,
Dec 10, 2007, 5:02:32 PM12/10/07
to
On Dec 10, 10:07 am, Q...@domain.invalid wrote:
> spamb...@milmac.com (Doug Miller) wrote in message-id: <dH97j.76990$YL5.33...@newssvr29.news.prodigy.net>

I think the user just wants to be able to send binary data. This
algorithm sounds way over the top of what he's asking.

In short, to send an integer using n bytes in a conventional manner,
the integer will need to be between 0 and 2^(8*n) - 1. One byte will
accommodate an integer between 0 and 255. Two bytes will accommodate
an integer between 0 and 65535. Three bytes will... Well, you get
the idea.

I think smallpond has the exact answer the OP is looking for.

0 new messages